npm install webpack --save-dev 报错:npm ERR! Unexpected end of JSON input while parsing near 解决

 

npm init 后,执行 npm install webpack --save-dev 时,报错:

macs@DESKTOP-0C5KBG1 MINGW64 /f/study/webpack-test
$ npm install webpack --save-dev
npm ERR! Unexpected end of JSON input while parsing near '...SDI\nP1t9j3SP+Baudh9f'

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

然后找了下很多说用如下方案:

就是 npm cache clean –force 一下就可以了,但是清除缓存试了后,没效果,还是报上面的错;

 

然后找到另一种方式解决了:

第一步:npm install -g cnpm --registry=https://registry.npm.taobao.org

macs@DESKTOP-0C5KBG1 MINGW64 /f/study/webpack-test
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
C:\Users\macs\AppData\Roaming\npm\cnpm -> C:\Users\macs\AppData\Roaming\npm\node_modules\cnpm\bin\cnpm
+ [email protected]
added 637 packages in 50.545s

第二步:cnpm install webpack -g

macs@DESKTOP-0C5KBG1 MINGW64 /f/study/webpack-test
$ cnpm install webpack -g
Downloading webpack to C:\Users\macs\AppData\Roaming\npm\node_modules\webpack_tmp
Copying C:\Users\macs\AppData\Roaming\npm\node_modules\webpack_tmp\[email protected]@webpack to C:\Users\macs\AppData\Roaming\npm\node_modules\webpack
Installing webpack's dependencies to C:\Users\macs\AppData\Roaming\npm\node_modules\webpack/node_modules
[1/24] @webassemblyjs/[email protected] installed at node_modules\_@[email protected]@@webassemblyjs\helper-module-context
[2/24] chrome-trace-event@^1.0.0 installed at node_modules\[email protected]@chrome-trace-event
[3/24] ajv-keywords@^3.1.0 installed at node_modules\[email protected]@ajv-keywords
[4/24] acorn@^5.6.2 installed at node_modules\[email protected]@acorn
[5/24] acorn-dynamic-import@^3.0.0 installed at node_modules\[email protected]@acorn-dynamic-import
[6/24] memory-fs@~0.4.1 existed at node_modules\[email protected]@memory-fs
[7/24] json-parse-better-errors@^1.0.2 installed at node_modules\[email protected]@json-parse-better-errors
[8/24] eslint-scope@^4.0.0 installed at node_modules\[email protected]@eslint-scope
[9/24] loader-runner@^2.3.0 installed at node_modules\[email protected]@loader-runner
[10/24] @webassemblyjs/[email protected] installed at node_modules\_@[email protected]@@webassemblyjs\ast
[11/24] @webassemblyjs/[email protected] installed at node_modules\_@[email protected]@@webassemblyjs\wasm-parser
[12/24] tapable@^1.1.0 existed at node_modules\[email protected]@tapable
[13/24] schema-utils@^0.4.4 installed at node_modules\[email protected]@schema-utils
[14/24] @webassemblyjs/[email protected] installed at node_modules\_@[email protected]@@webassemblyjs\wasm-edit
[15/24] enhanced-resolve@^4.1.0 installed at node_modules\[email protected]@enhanced-resolve
[16/24] mkdirp@~0.5.0 installed at node_modules\[email protected]@mkdirp
[17/24] ajv@^6.1.0 installed at node_modules\[email protected]@ajv
[18/24] neo-async@^2.5.0 installed at node_modules\[email protected]@neo-async
[19/24] loader-utils@^1.1.0 installed at node_modules\[email protected]@loader-utils
[20/24] webpack-sources@^1.3.0 installed at node_modules\[email protected]@webpack-sources
[21/24] node-libs-browser@^2.0.0 installed at node_modules\[email protected]@node-libs-browser
[22/24] micromatch@^3.1.8 installed at node_modules\[email protected]@micromatch
[23/24] terser-webpack-plugin@^1.1.0 installed at node_modules\[email protected]@terser-webpack-plugin
[email protected] download from binary mirror: {"module_name":"fse","module_path":"./lib/binding/{configuration}/{node_abi}-{platform}-{arch}/","remote_path":"./v{version}/","package_name":"{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz","host":"https://cdn.npm.taobao.org/dist/fsevents"}
platform unsupported [email protected][email protected] › fsevents@^1.2.2 Package require os(darwin) not compatible with your platform(win32)
[fsevents@^1.2.2] optional install error: Package require os(darwin) not compatible with your platform(win32)
[24/24] watchpack@^1.5.0 installed at node_modules\[email protected]@watchpack
Recently updated (since 2018-12-29): 2 packages (detail see file C:\Users\macs\AppData\Roaming\npm\node_modules\webpack\node_modules\.recently_updates.txt)
  2019-01-04
    → [email protected] › terser@^3.8.1(3.14.1) (05:57:54)
  2019-01-03
    → [email protected][email protected] › rimraf@^2.6.2(2.6.3) (03:26:12)
All packages installed (292 packages installed from npm registry, used 4s(network 4s), speed 1.29MB/s, json 268(443.31kB), tarball 4.27MB)
[[email protected]] link C:\Users\macs\AppData\Roaming\npm\webpack@ -> C:\Users\macs\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js

第三步:cnpm install --global vue-cli

 

最后:cnpm install webpack --save-dev 搞定:

macs@DESKTOP-0C5KBG1 MINGW64 /f/study/webpack-test
$ cnpm install webpack --save-dev
platform unsupported [email protected][email protected][email protected] › fsevents@^1.2.2 Package require os(darwin) not compatible with your platform(win32)
[fsevents@^1.2.2] optional install error: Package require os(darwin) not compatible with your platform(win32)
√ Installed 1 packages
√ Linked 268 latest versions
√ Run 0 scripts
Recently updated (since 2018-12-29): 3 packages (detail see file F:\study\webpack-test\node_modules\.recently_updates.txt)
√ All packages installed (293 packages installed from npm registry, used 19s(network 19s), speed 257.61kB/s, json 269(493.65kB), tarball 4.27MB)

 

你可能感兴趣的:(webpack)