编译失败。webpack 不是一个函数

IT技术 reactjs npm npm-start
2021-05-10 02:17:09

我的项目运行良好,但在安装 react-redux 和 redux 后,我无法启动该项目,它向我显示此错误

编译失败。

webpack 不是一个函数

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@0.1.0 start script.

npm 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。

终端报错截图

2个回答

在升级我的所有节点module(包括 react 和 redux,但特别是 react-dev-utils 到 v8.0.0)后,我遇到了相同症状的问题。createCompiler()函数已更改为期望一个对象而不是多个参数(我想这将在未来提供更大的灵活性)。

我改变了我的 start.js 从:

const compiler = createCompiler(webpack, config, appName, urls, useYarn);

到:

const compiler = createCompiler({ webpack, config, appName, urls, useYarn });

简单的 npm install 命令对我有用