解决npm run dev失败的问题

先说一下,我是在什么情况下遇到这个问题。我打算在公司电脑上,从gitHub上面clone一份我的vue脚手架demo修改运行,这份代码我在自己的电脑上运行npm run dev 是可以成功的,但是在公司的电脑就报了以下的错误:

D:\vue-playlist>npm run dev

> vue-playlist@1.0.0 dev D:\vue-playlist
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue-playlist@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-playlist@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2019-02-01T03_26_31_312Z-debug.log

看了一下报错信息,说我的node_module包丢了
然后我就百度了一堆解决方法
都是说
npm install
npm run build
npm run dev
就可以解决~
我运行了一下

cnpm install

是不可以的~~~~
运行完npm install之后出现了如下报错:

D:\vue-playlist>npm install

> uglifyjs-webpack-plugin@0.4.6 postinstall D:\vue-playlist\node_modules\webpack\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js

npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN The package vue-router is included as both a dev and production dependency.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 865 packages from 478 contributors, updated 28 packages and audited 10653 packages in 160.56s
found 2 vulnerabilities (1 moderate, 1 high)
  run `npm audit fix` to fix them, or `npm audit` for details

看了很多贴子也没说什么方法,走投无路的我就认真看了一下这个报错,最后一行让我尝试一下修复,找到了两个漏洞,一个中级、一个高级~于是我就运行了一下下面的代码:

npm audit fix
D:\vue-playlist>npm audit fix
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN The package vue-router is included as both a dev and production dependency.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

up to date in 8.922s
fixed 0 of 2 vulnerabilities in 10653 scanned packages
  2 package updates for 2 vulns involved breaking changes
  (use `npm audit fix --force` to install breaking changes; or refer to `npm audit` for steps to fix these manually)

执行完这个,我运行npm run dev其实就已经可以了~
一般人走到这步就成功了,下面可以不看,哈哈哈

但是我突然又看到
最后一行又让我运行一下:

npm audit fix --force
D:\vue-playlist>npm audit fix --force
npm WARN using --force I sure hope you know what you are doing.

> fsevents@1.2.4 install D:\vue-playlist\node_modules\fsevents
> node install

npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.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-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 The package vue-router is included as both a dev and production dependency.

+ url-loader@1.1.2
+ webpack-dev-server@3.1.14
added 116 packages from 46 contributors, removed 80 packages and updated 18 packages in 42.166s
fixed 2 of 2 vulnerabilities in 10653 scanned packages
  2 package updates for 2 vulns involved breaking changes
  (installed due to `--force` option)

然后我再来尝试运行:

D:\vue-playlist>npm run dev

> vue-playlist@1.0.0 dev D:\vue-playlist
> 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> (D:\vue-playlist\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-playlist@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-playlist@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\Admin\AppData\Roaming\npm-cache\_logs\2019-02-01T03_14_01_137Z-debug.log

好了,gg了,以失败告终
于是我又重新来

D:\vue-playlist>cnpm install
| [29/37] Installing postcss-load-plugins@^2.3.0platform unsupported babel-loader@7.1.5 › webpack@3.12.0 › watchpack@1.6.0 › chokidar@2.0.4 › fsevents@^1.2.2 Package require os(darwin) not compatible with your platform(win32)
/ [30/37] Installing bluebird@^3.1.1[fsevents@^1.2.2] optional install error: Package require os(darwin) not compatible with your platform(win32)
√ Installed 37 packages
√ Linked 714 latest versions
[1/1] scripts.postinstall babel-loader@7.1.5 › webpack@3.12.0 › uglifyjs-webpack-plugin@^0.4.6 run "node lib/post_install.js", root: "D:\\vue-playlist\\node_modules\\_uglifyjs-webpack-plugin@0.4.6@uglifyjs-webpack-plugin"
[1/1] scripts.postinstall babel-loader@7.1.5 › webpack@3.12.0 › uglifyjs-webpack-plugin@^0.4.6 finished in 94ms
√ Run 1 scripts
deprecate autoprefixer@7.2.6 › browserslist@^2.11.3 Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
deprecate css-loader@0.28.11 › cssnano@3.10.0 › autoprefixer@6.7.7 › browserslist@^1.7.6 Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
deprecate webpack-bundle-analyzer@2.13.1 › bfj-node4@^5.2.0 Switch to the `bfj` package for fixes and new features!
Recently updated (since 2019-01-25): 6 packages (detail see file D:\vue-playlist\node_modules\.recently_updates.txt)
  Today:
    → autoprefixer@7.2.6 › browserslist@2.11.3 › electron-to-chromium@^1.3.30(1.3.111) (09:02:30)
√ All packages installed (857 packages installed from npm registry, used 36s(network 35s), speed 530.41kB/s, json 751(1.58MB), tarball 16.55MB)

这边显示 all packages installed~
Let’s go!!!运行

D:\vue-playlist>npm run build

> vue-playlist@1.0.0 build D:\vue-playlist
> node build/build.js

Hash: c93cef60b22413c24c60
Version: webpack 3.12.0
Time: 5655ms
                                                  Asset       Size  Chunks             Chunk Names
                           static/img/pizza.1329a52.jpg     234 kB          [emitted]
                  static/js/app.80646c69c3b745342f6a.js    8.56 kB       0  [emitted]  app
               static/js/vendor.30617586dae3cb97abf9.js     113 kB       1  [emitted]  vendor
             static/js/manifest.2ae2e69a05c33dfc65f8.js  857 bytes       2  [emitted]  manifest
    static/css/app.d0bf4887a9779e516e8a39eff7cca103.css  244 bytes       0  [emitted]  app
static/css/app.d0bf4887a9779e516e8a39eff7cca103.css.map  722 bytes          [emitted]
              static/js/app.80646c69c3b745342f6a.js.map    53.7 kB       0  [emitted]  app
           static/js/vendor.30617586dae3cb97abf9.js.map     559 kB       1  [emitted]  vendor
         static/js/manifest.2ae2e69a05c33dfc65f8.js.map    4.97 kB       2  [emitted]  manifest
                                             index.html  706 bytes          [emitted]

  Build complete.

  Tip: built files are meant to be served over an HTTP server.
  Opening index.html over file:// won't work.


D:\vue-playlist>npm run dev

> vue-playlist@1.0.0 dev D:\vue-playlist
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

 15% building modules 42/60 modules 18 active ...mponents\about\contact\PersonName 95% emitting

 DONE  Compiled successfully in 2914ms                                                                                                                          11:30:08

 I  Your application is running here: http://localhost:8080

成功了!!!!!!!!!!!!!!
哈哈哈,也没有很多时间来研究这个,所以就先记录一下吧,以后再看看。

引用:cd vue-admin-template # 安装依赖 npm install # 建议不要直接使用 cnpm 安装以来,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题 npm install --registry=https://registry.npm.taobao.org # ...。 引用:Vue元素管理模板 English | 具有Element UI,axios,iconfont,权限控制和lint的最小vue管理员模板 ...npm run dev 这将自动打开 建造 # build for test environment npm run build:stage # build for。 引用:电脑中有之前的vue-element-admin 模板,可以正常的运行,但是拉取最新版运行时提示如下错误 错误内容 DONE Compiled successfully in 4163ms 4:26:31 ├F10: PM┤ App running at: - Local: http://localhost:9528 - Network: http://192.168.70.192:9528 Note that the development build is not optimized. To create a production build, run npm run build. events.js:291 throw er; // Unhandled 'error' event ^ Error: spawn cmd ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:84:21) Emitted 'error' event on ChildProcess instance at: at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:84:21) { errno: 'ENOENT', code: 'ENOENT', syscall: 'spawn cmd', path: 'cmd', spawnargs: [ '/c', 'start', '""', '/b', 'http://localhost:9528' ] } 解决办法 。 运行`npm run dev`失败的原因是没有找到`cmd`命令。`cmd`是Windows系统中一个重要的命令行解释程序,它负责执行命令提示符窗口中输入的指令。解决问题的方法是确保你的系统中存在`cmd`命令并且可以正常使用。 另外,你还可以尝试以下操作: 1. 确保你的系统环境变量中包含`cmd`命令的路径。 2. 检查你的系统是否安装了`cmd`命令。如果没有安装,你可以通过安装Windows的修复工具来修复此问题。 3. 如果你的系统中已经存在`cmd`命令,但是仍然无法运行`npm run dev`,可能是由于权限问题导致的。你可以尝试以管理员身份运行命令提示符窗口,并再次运行`npm run dev`命令。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值