自在猫先生 2023-03-12 21:54 采纳率: 62.9%
浏览 45
已结题

node js打包的时候安装模块安不上提示异常

我在使用node js安装模块的时候,提示已经安装成功了,但是在使用webpack打包的时候又报错了。

报错内容:
PS C:\Users\Administrator\Desktop\Node_Word> npx webpack        
assets by status 1.33 MiB [cached] 1 asset
orphan modules 1.67 MiB [orphan] 298 modules
runtime modules 1.02 KiB 6 modules
modules by path ./node_modules/ 3.95 MiB
  javascript modules 3.86 MiB
    cacheable modules 3.86 MiB 313 modules
    optional modules 320 bytes [optional] 2 modules
  json modules 89.9 KiB
    ./node_modules/tedious/package.json 3.23 KiB [built] [code generated]
    ./node_modules/iconv-lite/encodings/tables/shiftjis.json 8.78 KiB [built] [code generated]
    + 7 modules
./js/server.js 9.67 KiB [built] [code generated]
stream (ignored) 15 bytes [optional] [built] [code generated]
./util.inspect (ignored) 15 bytes [built] [code generated]
util (ignored) 15 bytes [built] [code generated]
util (ignored) 15 bytes [built] [code generated]

WARNING in ./node_modules/defaultable/defaultable.js 49:13-31
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/hbo-dnsd/server.js 5:0-22
 @ ./node_modules/hbo-dnsd/named.js 6:20-39
 @ ./node_modules/dns/lib/dns.js 2:17-36
 @ ./node_modules/tedious/lib/connection.js 12:34-48
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value.
Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

1 warning has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

ERROR in ./node_modules/js-md4/src/md4.js 117:17-34
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\js-md4\src'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }
 @ ./node_modules/tedious/lib/ntlm-payload.js 12:35-52
 @ ./node_modules/tedious/lib/connection.js 36:42-67
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

ERROR in ./node_modules/native-dns-cache/lookup.js 21:12-28
Module not found: Error: Can't resolve 'dgram' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\native-dns-cache'
 @ ./node_modules/native-dns-cache/index.js 3:0-50 4:0-60 5:0-68
 @ ./node_modules/native-dns/lib/platform.js 28:12-39
 @ ./node_modules/native-dns/dns.js 23:0-44
 @ ./node_modules/dns/lib/dns.js 3:17-38
 @ ./node_modules/tedious/lib/connection.js 12:34-48
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

ERROR in ./node_modules/native-dns/lib/platform.js 23:9-22
Module not found: Error: Can't resolve 'fs' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\native-dns\lib'
 @ ./node_modules/native-dns/dns.js 23:0-44
 @ ./node_modules/dns/lib/dns.js 3:17-38
 @ ./node_modules/tedious/lib/connection.js 12:34-48
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

ERROR in ./node_modules/native-dns/lib/server.js 23:12-28
Module not found: Error: Can't resolve 'dgram' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\native-dns\lib'
 @ ./node_modules/native-dns/dns.js 25:0-59 26:0-65 27:0-65
 @ ./node_modules/dns/lib/dns.js 3:17-38
 @ ./node_modules/tedious/lib/connection.js 12:34-48
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

ERROR in ./node_modules/native-dns/lib/utils.js 21:12-28
Module not found: Error: Can't resolve 'dgram' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\native-dns\lib'
 @ ./node_modules/native-dns/lib/server.js 27:16-44 28:16-44
 @ ./node_modules/native-dns/dns.js 25:0-59 26:0-65 27:0-65
 @ ./node_modules/dns/lib/dns.js 3:17-38
 @ ./node_modules/tedious/lib/connection.js 12:34-48
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

ERROR in ./node_modules/tedious/lib/connection.js 8:37-54
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\tedious\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

ERROR in ./node_modules/tedious/lib/ntlm-payload.js 10:37-54
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\tedious\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }
 @ ./node_modules/tedious/lib/connection.js 36:42-67
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

ERROR in ./node_modules/tedious/lib/sender.js 9:36-52
Module not found: Error: Can't resolve 'dgram' in 'C:\Users\Administrator\Desktop\Node_Word\node_modules\tedious\lib'
 @ ./node_modules/tedious/lib/instance-lookup.js 13:14-33
 @ ./node_modules/tedious/lib/connection.js 26:22-50
 @ ./node_modules/tedious/lib/tedious.js 59:41-64
 @ ./js/server.js 175:17-46

8 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.76.1 compiled with 8 errors and 2 warnings in 27216 ms

img

img

img

img

  • 写回答

2条回答 默认 最新

  • MarkHan_ 2023-03-12 22:10
    关注

    该回答引用GPTᴼᴾᴱᴺᴬᴵ
    这个错误看起来像是由于缺少一些 Node.js 核心模块而导致的问题。具体来说,js-md4 模块需要 Node.js 的 crypto 模块,而 native-dns-cache 模块需要 Node.js 的 dgram 和 fs 模块。Webpack 5 不再默认为这些模块提供 polyfill,因此需要手动配置这些模块的 polyfill。

    要解决这个问题,您可以在 Webpack 配置中添加以下内容:

    resolve: {
      fallback: {
        crypto: require.resolve('crypto-browserify'),
        dgram: require.resolve('dgram-browserify'),
        fs: require.resolve('browserify-fs'),
      },
    },
    
    
    

    然后,您需要在项目中安装这些 polyfill:

    npm install crypto-browserify dgram-browserify browserify-fs
    
    
    

    如果您仍然遇到其他问题,请尝试运行 npm install 来重新安装所有依赖项,并确保您的 Node.js 版本是最新的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月20日
  • 已采纳回答 3月12日
  • 创建了问题 3月12日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来