1. 程式人生 > >npm run server報錯原因之一:Cannot find module 'webpack-cli/bin/config-yargs'

npm run server報錯原因之一:Cannot find module 'webpack-cli/bin/config-yargs'

使用npm run dev啟動server時報錯:
C:\Users\Administrator\daqixin-product\health-platform\health-wx-web>npm run dev

> [email protected] dev C:\Users\Administrator\daqixin-product\health-platform\health-wx-web
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

The CLI moved into a separate package: webpack-cli
Please install 'webpack-cli' in addition to webpack itself to use the CLI
-> When using npm: npm i -D webpack-cli
-> When using yarn: yarn add -D webpack-cli
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\webpack-dev-server\bin\webpack-dev-server.js:84:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 
[email protected]
dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] dev 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! C:\Users\Administrator\product\iulicai-dev\nodejs-env\node_cache\_logs\2019-01-06T08_25_50_539Z-debug.log

原因是找不到webpack-cli這個包,咱們使用npm新增此包即可:
E:\webpack_demo>npm install webpack-cli

> [email protected] postinstall C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\webpack-cli
> opencollective postinstall


     *** Thank you for using webpack-cli! ***

Please consider donating to our open collective
     to help us maintain this package.

  https://opencollective.com/webpack/donate

                    ***

npm WARN 
[email protected]
requires a peer of [email protected]^2.3.1 but none is installed. You must install peer dependencies yourself. npm WARN [email protected] requires a peer of [email protected]^4.0.0 but none is installed. You must install peer dependencies yourself. npm WARN [email protected] requires a peer of [email protected]^4.0.0 but none is installed. You must install peer dependencies yourself. npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself. + [email protected] added 92 packages from 68 contributors, updated 1 package and audited 10044 packages in 41.374s found 4 moderate severity vulnerabilities run `npm audit fix` to fix them, or `npm audit` for details

然後再執行npm run dev:
E:\webpack_demo>npm run dev

> [email protected] dev C:\Users\Administrator\daqixin-product\health-platform\health-wx-web
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv-keywords\keywords\instanceof.js:52
    throw new Error('invalid "instanceof" keyword value ' + c);
    ^

Error: invalid "instanceof" keyword value Promise
    at getConstructor (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv-keywords\keywords\instanceof.js:52:11)
    at Ajv.compile (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv-keywords\keywords\instanceof.js:21:27)
    at Object.useCustomRule (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\compile\index.js:274:26)
    at Object.generate_custom [as code] (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\dotjs\custom.js:32:24)
    at Object.generate_validate [as validate] (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\dotjs\validate.js:347:35)
    at Object.generate_anyOf [as code] (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\dotjs\anyOf.js:34:27)
    at generate_validate (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\dotjs\validate.js:347:35)
    at localCompile (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\compile\index.js:87:22)
    at Ajv.compile (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\compile\index.js:56:13)
    at Ajv._compile (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\ajv.js:351:27)
    at Ajv.compile (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\ajv\lib\ajv.js:117:37)
    at validateObject (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\webpack\lib\validateSchema.js:36:23)
    at validateSchema (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\webpack\lib\validateSchema.js:31:10)
    at processConfiguredOptions (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\webpack-cli\bin\convert-argv.js:136:48)
    at module.exports (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\webpack-cli\bin\convert-argv.js:130:10)
    at Object.<anonymous> (C:\Users\Administrator\daqixin-product\health-platform\health-wx-web\node_modules\webpack-dev-server\bin\webpack-dev-server.js:92:55)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev 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!     C:\Users\Administrator\product\iulicai-dev\nodejs-env\node_cache\_logs\2019-01-06T08_32_43_100Z-debug.log

Error: invalid “instanceof” keyword value Promise的解決方法
我的webpack版本是3.2,webpack-dev-serverk原來版本是3.1,我將webpack-dev-serverk降版為2.9.4就可以了。指定安裝命令如下:

npm install [email protected] --save-dev