Webpack 已使用与 API 架构不匹配的配置对象进行初始化



使用Ruby on Rails(6.1.4.4(,在webpack从4.46.0升级到5.67.0,webpack-cli从3.3.12升级到4.9.2后,不断出现以下错误:

root@b26d476dafbd:/myapp$ bin/webpack
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.node should be one of these:
false | object { __dirname?, __filename?, global? }
-> Include polyfills or mocks for various node stuff.
Details:
* configuration.node has an unknown property 'dgram'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
* configuration.node has an unknown property 'fs'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
* configuration.node has an unknown property 'net'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
* configuration.node has an unknown property 'tls'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
* configuration.node has an unknown property 'child_process'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.

下面是我的package.json:的一个例子

{
"name": "vspm",
"private": true,
"dependencies": {
"@claviska/jquery-minicolors": "^2.3.6",
"@rails/activestorage": "^7.0.1",
"@rails/ujs": "^7.0.1",
"@rails/webpacker": "5.4.3",
"add": "^2.0.6",
"bootstrap": "5.1.3",
"bootstrap4-tagsinput": "^4.1.3",
"bufferutil": "^4.0.6",
"cocoon": "github:nathanvda/cocoon#c24ba53",
"datatables.net": "^1.11.4",
"datatables.net-bs4": "^3.2.2",
"google-libphonenumber": "^3.2.26",
"intl-tel-input": "^17.0.15",
"jquery": "^3.6.0",
"jquery-mask-plugin": "^1.14.16",
"justgage": "^1.5.1",
"moment": "^2.29.1",
"node-waves": "^0.7.6",
"popper.js": "^1.16.1",
"raphael": "^2.3.0",
"textlint": "^12.1.0",
"utf-8-validate": "^5.0.8",
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2",
"yarn": "^1.22.17"
},
"description": "This README would normally document whatever steps are necessary to get the application up and running.",
"version": "1.0.0",
"main": "pdf.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/altjx/goku.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/altjx/goku/issues"
},
"homepage": "https://github.com/altjx/goku#readme",
"devDependencies": {
"@babel/plugin-transform-strict-mode": "^7.16.7",
"webpack-dev-server": "^4.7.3"
}
}

不太确定是什么原因导致升级。不幸的是,我甚至不确定错误消息指向哪里,也不确定这里的问题到底是什么。

看起来在webpack4中设置了节点polyfils,但在webpack5中自动删除了nodejs polyfills

在webpack5中设置polyfill的简单方法是npm i node polyfill webpack插件。在webpack.config.js

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
plugins: [
new NodePolyfillPlugin(),
],

最新更新