【问题标题】:Webpack - NodeJS - Module not found: Error: Can't resolve 'fs'Webpack - NodeJS - 找不到模块:错误:无法解析“fs”
【发布时间】:2018-08-21 10:39:39
【问题描述】:

使用 webpack 构建 nodejs 项目时出现以下错误。

ERROR in ./node_modules/mime/mime.js
Module not found: Error: Can't resolve 'fs' in 'C:\Sample\node-ts-sample\node_modules\mime'
 @ ./node_modules/mime/mime.js 2:9-22
 @ ./node_modules/send/index.js
 @ ./node_modules/express/lib/response.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./src/server.ts
 @ ./src/index.ts

【问题讨论】:

标签: node.js webpack


【解决方案1】:

这是一个节点应用程序。在 webpack 配置中添加了以下节点解决了我的问题

 target:'node',

我在https://jlongster.com/Backend-Apps-with-Webpack--Part-I参考了这篇文章

【讨论】:

  • 感谢您发布答案,我喜欢这种情况:)
【解决方案2】:

只需将其添加到您的 webpack 配置文件中:

const webpackConfig = {
  target: 'node'
};
module.exports = webpackConfig;

【讨论】:

    猜你喜欢
    • 2018-04-11
    • 2018-09-30
    • 2018-06-29
    • 2019-12-01
    • 2019-05-31
    • 2017-04-18
    • 2017-07-10
    • 2020-02-24
    相关资源
    最近更新 更多