记一次使用create react app出现webpack is not a function的情况

本文解决了一个在CentOS7环境下使用npm start命令启动应用时遇到的Webpack不是函数的问题。错误出现在更改了createCompiler函数的参数传递方式后。通过调整参数为对象形式解决了此问题。

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 有空的话可以看一下

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值