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

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日

悬赏问题

  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?
  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!