【发布时间】:2022-06-22 15:10:29
【问题描述】:
我经常收到此错误消息,但不知道如何解决它:
【问题讨论】:
我经常收到此错误消息,但不知道如何解决它:
【问题讨论】:
问题是 Webpack v5 不再为 Node.js 内置插件添加 polyfill,您应该选择:
如果您选择第二个选项,请使用我正在开发的Putout 代码转换器,它会在@putout/plugin-webpack 的帮助下为您解决所有问题。这是它的样子:
convert-node-to-resolve-fallback 修复 webpack 编译错误:
Module not found: Error: Can't resolve 'path'`
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.
不正确的代码:
module.exports = {
node: {
path: 'empty',
buffer: 'empty',
crypto: 'empty'
},
};
正确代码:
module.exports = {
resolve: {
fallback: {
path: false,
buffer: false,
crypto: false
},
},
};
【讨论】:
安装最新版本的 Node(当时是 Node v18.4.0)为我解决了这个问题,而无需执行任何额外的操作,例如安装和解析 polyfill。
【讨论】: