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

2019/01 05 14:01

 

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 '...SDInP1t9j3SP+Baudh9f'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UsersmacsAppDataRoamingnpm-cache_logs2019-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 socks@1.1.10: 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:UsersmacsAppDataRoamingnpmcnpm -> C:UsersmacsAppDataRoamingnpmnode_modulescnpmbincnpm
+ cnpm@6.0.0
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:UsersmacsAppDataRoamingnpmnode_moduleswebpack_tmp
Copying C:UsersmacsAppDataRoamingnpmnode_moduleswebpack_tmp_webpack@4.28.3@webpack to C:UsersmacsAppDataRoamingnpmnode_moduleswebpack
Installing webpack's dependencies to C:UsersmacsAppDataRoamingnpmnode_moduleswebpack/node_modules
[1/24] @webassemblyjs/helper-module-context@1.7.11 installed at node_modules_@webassemblyjs_helper-module-context@1.7.11@@webassemblyjshelper-module-context
[2/24] chrome-trace-event@^1.0.0 installed at node_modules_chrome-trace-event@1.0.0@chrome-trace-event
[3/24] ajv-keywords@^3.1.0 installed at node_modules_ajv-keywords@3.2.0@ajv-keywords
[4/24] acorn@^5.6.2 installed at node_modules_acorn@5.7.3@acorn
[5/24] acorn-dynamic-import@^3.0.0 installed at node_modules_acorn-dynamic-import@3.0.0@acorn-dynamic-import
[6/24] memory-fs@~0.4.1 existed at node_modules_memory-fs@0.4.1@memory-fs
[7/24] json-parse-better-errors@^1.0.2 installed at node_modules_json-parse-better-errors@1.0.2@json-parse-better-errors
[8/24] eslint-scope@^4.0.0 installed at node_modules_eslint-scope@4.0.0@eslint-scope
[9/24] loader-runner@^2.3.0 installed at node_modules_loader-runner@2.3.1@loader-runner
[10/24] @webassemblyjs/ast@1.7.11 installed at node_modules_@webassemblyjs_ast@1.7.11@@webassemblyjsast
[11/24] @webassemblyjs/wasm-parser@1.7.11 installed at node_modules_@webassemblyjs_wasm-parser@1.7.11@@webassemblyjswasm-parser
[12/24] tapable@^1.1.0 existed at node_modules_tapable@1.1.1@tapable
[13/24] schema-utils@^0.4.4 installed at node_modules_schema-utils@0.4.7@schema-utils
[14/24] @webassemblyjs/wasm-edit@1.7.11 installed at node_modules_@webassemblyjs_wasm-edit@1.7.11@@webassemblyjswasm-edit
[15/24] enhanced-resolve@^4.1.0 installed at node_modules_enhanced-resolve@4.1.0@enhanced-resolve
[16/24] mkdirp@~0.5.0 installed at node_modules_mkdirp@0.5.1@mkdirp
[17/24] ajv@^6.1.0 installed at node_modules_ajv@6.6.2@ajv
[18/24] neo-async@^2.5.0 installed at node_modules_neo-async@2.6.0@neo-async
[19/24] loader-utils@^1.1.0 installed at node_modules_loader-utils@1.2.3@loader-utils
[20/24] webpack-sources@^1.3.0 installed at node_modules_webpack-sources@1.3.0@webpack-sources
[21/24] node-libs-browser@^2.0.0 installed at node_modules_node-libs-browser@2.1.0@node-libs-browser
[22/24] micromatch@^3.1.8 installed at node_modules_micromatch@3.1.10@micromatch
[23/24] terser-webpack-plugin@^1.1.0 installed at node_modules_terser-webpack-plugin@1.2.1@terser-webpack-plugin
fsevents@1.2.4 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 watchpack@1.6.0 › chokidar@2.0.4 › 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_watchpack@1.6.0@watchpack
Recently updated (since 2018-12-29): 2 packages (detail see file C:UsersmacsAppDataRoamingnpmnode_moduleswebpacknode_modules.recently_updates.txt)
  2019-01-04
    → terser-webpack-plugin@1.2.1 › terser@^3.8.1(3.14.1) (05:57:54)
  2019-01-03
    → terser-webpack-plugin@1.2.1 › cacache@11.3.2 › 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)
[webpack@4.28.3] link C:UsersmacsAppDataRoamingnpmwebpack@ -> C:UsersmacsAppDataRoamingnpmnode_moduleswebpackbinwebpack.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 webpack@4.28.3 › watchpack@1.6.0 › chokidar@2.0.4 › 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:studywebpack-testnode_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)

 

--转载请注明: https://www.macs.vip/archives/49