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

本文介绍了一种解决npm在Windows环境下安装Webpack时遇到的JSON解析错误的方法。通过更换npm源至淘宝镜像并使用cnpm,成功安装了Webpack及依赖,解决了安装过程中的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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 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:\Users\macs\AppData\Roaming\npm\cnpm -> C:\Users\macs\AppData\Roaming\npm\node_modules\cnpm\bin\cnpm
+ 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:\Users\macs\AppData\Roaming\npm\node_modules\webpack_tmp
Copying C:\Users\macs\AppData\Roaming\npm\node_modules\webpack_tmp\_webpack@4.28.3@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/helper-module-context@1.7.11 installed at node_modules\_@webassemblyjs_helper-module-context@1.7.11@@webassemblyjs\helper-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@@webassemblyjs\ast
[11/24] @webassemblyjs/wasm-parser@1.7.11 installed at node_modules\_@webassemblyjs_wasm-parser@1.7.11@@webassemblyjs\wasm-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@@webassemblyjs\wasm-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:\Users\macs\AppData\Roaming\npm\node_modules\webpack\node_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:\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 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:\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)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员老油条

您的鼓励将是我创作的大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值