在CentOS 7下出现报错信息如下:
[root@VM_15_35_centos /data0/www/kfe/my-reat/client]npm start
> test@0.1.0 start /data0/www/kfe/my-reat/client
> node scripts/start.js
Failed to compile.
webpack is not a function
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-07-16T02_31_16_759Z-debug.log
报错提示:webpack is no function
报错信息文件:npm ERR! test@0.1.0 start: `node scripts/start.js`
打开文件会有:

将react-dev-utils升级到v8.0.0之后。createCompiler()函数已更改为期望对象而不是多个参数(笔者认为这将在未来提供更大的灵活性)
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
更改为对象 createCompiler({}):
const compiler = createCompiler({ webpack, config, appName, urls, useYarn })
这里笔者发现一篇 create-react-app 源码解析之react-scripts 有空的话可以看一下
本文解决了一个在CentOS7环境下使用npm start命令启动应用时遇到的Webpack不是函数的问题。错误出现在更改了createCompiler函数的参数传递方式后。通过调整参数为对象形式解决了此问题。

6498

被折叠的 条评论
为什么被折叠?



