找不到模块:错误:无法解析“/home/user/Desktop/all/editor/node_modules/winston/dist/winston”中的“fs”

时间:2021-02-18 08:11:26

标签: node.js webpack fs winston

我试图将 winston 记录器添加到项目中,但收到以下错误:

ERROR in ./node_modules/winston/dist/winston/tail-file.js
Module not found: Error: Can't resolve 'fs' in '/home/user/Desktop/all/editor/node_modules/winston/dist/winston'
 @ ./node_modules/winston/dist/winston/tail-file.js 9:9-22
 @ ./node_modules/winston/dist/winston/transports/file.js
 @ ./node_modules/winston/dist/winston/transports/index.js
 @ ./node_modules/winston/dist/winston.js
 @ ./winston.js
 @ ./client/modules/App/App.jsx
 @ ./client/routes.jsx
 @ ./client/index.jsx
 @ multi core-js/modules/es6.promise core-js/modules/es6.array.iterator webpack-hot-middleware/client react-hot-loader/patch ./client/index.jsx

ERROR in ./node_modules/winston/dist/winston/transports/file.js
Module not found: Error: Can't resolve 'fs' in '/home/user/Desktop/all/editor/node_modules/winston/dist/winston/transports'
 @ ./node_modules/winston/dist/winston/transports/file.js 33:9-22
 @ ./node_modules/winston/dist/winston/transports/index.js
 @ ./node_modules/winston/dist/winston.js
 @ ./winston.js
 @ ./client/modules/App/App.jsx
 @ ./client/routes.jsx
 @ ./client/index.jsx
 @ multi core-js/modules/es6.promise core-js/modules/es6.array.iterator webpack-hot-middleware/client react-hot-loader/patch ./client/index.jsx

我已经尝试在 webpack 配置文件中添加 node: { fs: 'empty' } 并且还尝试了 target: 'node' 。它不起作用。

1 个答案:

答案 0 :(得分:0)

就我而言,我在浏览器环境中导入了 winston,但 winston 尚不支持浏览器环境。 在此处查看 shawnxusy 的评论:https://github.com/winstonjs/winston/issues/925

相关问题