先说一下,我是在什么情况下遇到这个问题。我打算在公司电脑上,从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

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

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐