【问题标题】:How to export one file to NodeJS and ReactJS?如何将一个文件导出到 NodeJS 和 ReactJS?
【发布时间】:2020-10-22 00:48:15
【问题描述】:

我正在尝试将一个对象数组文件导出到 nodeJS 和 ReactJS。

例如:

config.js

const config = {
  mode: "active", 
}
export default config;

我需要将它导入到 nodeJS 文件中。当时它在导出标签上显示错误。

我试过这样:

    exports.config = {
      mode: "active", 
    }
    //export default config;

它在 nodeJS 上工作。但我不能用这个文件做出反应。是否有任何可能的方式为两者使用相同的文件。

注意:节点版本:v12.13.0

【问题讨论】:

  • 尝试使用import { config } from './config'导入配置文件

标签: node.js reactjs object


【解决方案1】:

在使用exports.config的情况下,可以通过使用访问配置文件

import { config } from './config`

如果您想像在export default config 中一样将config 作为默认导出,请使用module.exports = config

【讨论】:

  • 当我使用module.exports = config 时,我无法从节点访问对象项并做出反应。
  • 你确定你导入正确吗?使用import config from './config' 导入并确保使用module.exports = config
  • 查看sandbox
猜你喜欢
  • 2019-01-31
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
  • 2021-11-02
  • 2019-09-08
  • 2020-10-18
  • 2021-05-10
  • 1970-01-01
相关资源
最近更新 更多