【问题标题】:Error loading 'Module'加载“模块”时出错
【发布时间】:2020-05-17 11:52:48
【问题描述】:

我正在捆绑一个 typescript 项目,但 webpack 失败并出现错误 ERROR in (webpack)/lib/NormalModule.js Module not found: Error: Can't resolve 'module' in 'C:\SPA\MyApp\node_modules\webpack\lib' @ (webpack)/lib/NormalModule.js 91:16-33

如果我从 var Module = require("module"); var Module = require("./module"); 问题解决了。

有没有人知道是什么导致了这个问题?没有其他人将其报告为问题似乎很奇怪。 有问题的行在这里: https://github.com/webpack/webpack/blob/master/lib/NormalModule.js#L90

【问题讨论】:

  • 你有没有想过这个问题?
  • 我依稀记得它被 WebPack 中的后续补丁解决了。

标签: webpack


【解决方案1】:

确保在resolve.modules数组中配置了正确的路径。

对于这个文件:

a/b/c/d/file.js

你需要在你的 webpack.config.js 中:

resolve: {
    extensions: ['.js'],
    modules: ['./a/b/c']
}

Webpack 将尝试解析你的绝对导入,反对那些路径 + node_modules。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。

    NormalModule.js Module not found: Can't resolve 'module'
    

    在尝试了一切之后,最后我不得不:

    • 删除 node_modules 文件夹
    • 运行 npm 缓存验证
    • 当应用运行时,revert package-lock.json 为最后一次提交。 (不仅仅是删除文件,而是revert
    • npm 安装

    我希望这对某人有帮助:)

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-13
      • 1970-01-01
      • 2019-09-26
      • 2010-12-17
      • 2018-03-05
      • 2016-08-04
      相关资源
      最近更新 更多