类型错误:无法使用 ReactJs 在 webpack-cli 中读取未定义的属性“presetToOptions" [英] TypeError: Cannot read property 'presetToOptions' of undefined in webpack-cli with ReactJs
问题描述
我正在开发 ReactJS 应用程序并配置了 "webpack": "^2.7.0"
,"webpack-cli": "^2.0.9
" 但是在从 cmd 运行 webpack 时出现以下错误.
I am working on ReactJS application and configured "webpack": "^2.7.0"
,
"webpack-cli": "^2.0.9
" but while running the webpack from cmd it has the following error.
const statsPresetToOptions = require("webpack").Stats.presetToOptions;
^
TypeError: Cannot read property 'presetToOptions' of undefined
at processOptions (F:\reactJs_weather\React-Weather-App\node_modules\webpack-cli\bin\webpack.js:284:57)
你有什么想法吗?
推荐答案
webpack-cli
需要 至少 webpack
version 4 运行.
如果您使用的是旧版本,如 webpack 2 或 3,则无需单独添加 webpack-cli
包.它已经内置于旧版本的 webpack
本身.
If you're using older version like webpack 2 or 3, you don't need to add webpack-cli
package seperately. It comes already built in with older versions of webpack
itself.
从第 4 版开始,整个 CLI 已被移植到一个单独的包 webpack-cli
中.
From version 4, the entire CLI has been ported inside a separate package webpack-cli
.
修复应该是删除 webpack-cli
包或使用最新版本的 webpack>=4
.
The fix should be to remove webpack-cli
package or use latest version of webpack>=4
.
有一个 正在进行的 PR 关于将 webpack 4 添加为对等依赖项,很快会弹出一个大致相同的警告.
There's an ongoing PR about adding webpack 4 as peer dependency, so soon there would a warning popping up about the same.
相关讨论:webpack 没有被列为 peer、添加 webpack 4 作为对等依赖
这篇关于类型错误:无法使用 ReactJs 在 webpack-cli 中读取未定义的属性“presetToOptions"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!