【问题标题】:Import json file in node.js(Express) and export to index.jsx(React)在 node.js(Express) 中导入 json 文件并导出到 index.jsx(React)
【发布时间】:2019-12-16 17:34:30
【问题描述】:

我想将一个 json 文件导入到我的 server.js 文件中,然后将其导出。然后将导出的数据导入我的 index.jsx 文件中。我能够将 json 数据提取到我的 server.js 文件中,并且还尝试使用 export.modulesexport default config 将其导出,但在我的 index.jsx 文件中导入它时出现错误。

ERROR in ./node_modules/destroy/index.js
Module not found: Error: Can't resolve 'fs' in 'D:\React Projects\SearchUI\node_modules\destroy'

ERROR in ./node_modules/send/index.js
Module not found: Error: Can't resolve 'fs' in 'D:\React Projects\SearchUI\node_modules\send'

ERROR in ./node_modules/express/lib/request.js
Module not found: Error: Can't resolve 'net' in 'D:\React Projects\SearchUI\node_modules\express\lib

以下是我到目前为止尝试的代码: server.js

const confiq = require("../public/json/config.json");
module.exports = config;

index.jsx

import config from "../server/server";
console.log(config);

【问题讨论】:

标签: javascript node.js reactjs express


【解决方案1】:

这应该是:

// server.js
const confiq = require("../public/json/config.json");
module.exports = config; // exporting the config 

// index.jsx

import confiq from "../server/server"; // importing the config
console.log(confiq);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-02
    • 2018-07-17
    • 2016-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多