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

> vue-mall@1.0.0 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! vue-mall@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-mall@1.0.0 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

> webpack-cli@3.2.0 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 less-loader@4.0.5 requires a peer of less@^2.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-dev-middleware@3.4.0 requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-dev-server@3.1.14 requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-cli@3.2.0 requires a peer of webpack@4.x.x but none is installed. You must install peer dependencies yourself.

+ webpack-cli@3.2.0
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

> vue-mall@1.0.0 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! vue-mall@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-mall@1.0.0 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 webpack-dev-server@2.9.4 --save-dev

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个错误通常发生在使用Webpack时,因为Webpack CLI没有正确安装或配置。是的,这个错误通常发生在使用Webpack时,因为Webpack CLI没有正确安装或配置。Webpack CLI是一个命令行工具,用于在命令行中运行Webpack命令。如果Webpack CLI没有正确安装或配置,它可能无法找到所需的模块,从而导致出现类似“cannot find module 'webpack-cli/bin/config-yargs'”的错误。 解决这个问题的方法包括: 1. 确认你已经全局安装了webpack-cli:在命令行中输入“npm list -g webpack-cli”,检查webpack-cli是否已经安装。如果没有安装,可以通过“npm install -g webpack-cli”来全局安装webpack-cli。 2. 确认你的项目中已经安装了webpack-cli:在项目的根目录下,运行“npm list webpack-cli”,检查webpack-cli是否已经安装。如果没有安装,可以通过“npm install webpack-cli --save-dev”来安装webpack-cli。 3. 确认你的webpack配置文件是否正确:检查webpack.config.js文件中是否正确地配置了webpackwebpack-cli。 4. 如果上述方法都没有解决问题,可以尝试更新npm和node.js版本,然后重新安装webpack-cli。 ### 回答2: 这个错误是由于缺少webpack-cli模块中的bin/config-yargs文件所引起的。webpack-cliwebpack的命令行工具,用于执行webpack命令。当我们执行webpack命令时,会查找webpack-cli模块,并在其中查找bin/config-yargs文件。如果找不到这个文件,就会抛出"cannot find module 'webpack-cli/bin/config-yargs'"的错误。 要解决这个问题,我们可以尝试以下几个方法: 1. 检查webpack-cli模块是否已安装:首先确保你已经在项目中安装了webpack-cli模块。可以通过在命令行中执行npm ls webpack-cli命令来检查。 2. 版本兼容性问题:如果你已经安装了webpack-cli模块,但仍然出现错误,可能是由于版本兼容性问题导致的。尝试安装或更新webpack-cli模块的最新版本,可以使用npm install webpack-cli@latest命令来更新。 3. 清除缓存:有时候,在安装或升级模块后,旧的缓存文件可能会导致错误。可以尝试清除npm缓存,使用npm cache clean命令清除缓存,然后重新安装webpack-cli模块。 如果以上方法都没有解决问题,可能是其他相关配置文件出现了问题,可以检查webpack配置文件是否正确,并确保相关依赖模块已安装。 总之,错误"cannot find module 'webpack-cli/bin/config-yargs'"通常是由于缺少或损坏的webpack-cli模块所引起的。通过检查模块是否安装、更新模块版本、清除缓存等方法,可以尝试解决这个问题。如果问题仍然存在,可能需要进一步检查其他配置文件或依赖项。 ### 回答3: 这个错误提示表示无法找到模块'webpack-cli/bin/config-yargs'。这通常是因为没有正确安装或配置WebpackCLI(命令行工具)。 要解决这个问题,可以尝试以下几个步骤: 1. 确认安装了webpack-cli模块:在命令行中输入`npm install webpack-cli -g`或`yarn global add webpack-cli`来全局安装webpack-cli模块。如果之前已经安装过,可以尝试卸载并重新安装。 2. 检查Webpack的配置文件:确认项目根目录中是否存在webpack.config.js或其他Webpack的配置文件。如果没有,则需要创建一个。 3. 更新Webpack的版本:如果已经安装了旧版本的Webpack,尝试更新到最新版本。可以使用`npm update webpack`或`yarn upgrade webpack`来更新。 4. 清除缓存并重新安装依赖:有时候,缓存中的某些文件可能导致问题。可以尝试使用`npm cache clean`或`yarn cache clean`来清除缓存,并重新安装项目的依赖。 5. 确保正确执行Webpack命令:在命令行中输入`webpack`来执行Webpack命令。确保正确使用了Webpack的命令行参数和选项。 如果以上步骤都无法解决问题,可以尝试搜索类似的错误信息,查看其他开发者的解决方案,或提交问题到相关社区寻求帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值