问题
when i run the script it show me this errors Here is error:
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: { "util"
: require.resolve("util
/") }', install 'util'
;
If you don't want to include a polyfill, you can use an empty module like this:resolve.fallback: { "util"
: false }
@ ./node_modules/webpack
/lib/index.js 74:30-50 77:9-29
@ ./src/googlesheets.js 21:16-34
@ ./src/index.js 1:0-44 2:0-10
回答1:
The main problem is with Webpack 5. It doesn't preload the polyfill of Node.js. I see that this issue can help you. https://github.com/webpack/webpack/issues/11282
To solve it: npm install util
, and add it into webpack.config.js
:
module.exports = {
// ...
resolve: {
fallback: {
util: require.resolve("util/")
}
}
// ...
};
回答2:
If your code is multi-target (node & browser), follow the other answers. If your code will only run on nodejs, this suffices:
module.exports = {
target: "node", // Or "async-node"
mode: "production" /* or "development", or "none" */
/* ... */
}
回答3:
This helped me:
npm install util
and then change webpack config to include:
module.exports = {
...
resolve: {
alias: {
util: require.resolve("util/")
}
}
};
来源:https://stackoverflow.com/questions/64402821/module-not-found-error-cant-resolve-util-in-webpack