NPM |安装模块时出错

时间:2018-07-30 09:32:12

标签: node.js npm

当我尝试安装一些模块时,出现此错误:

  

npm错误!解析附近时JSON输入意外结束   '...“ hjs”:“〜0.0.6”,“标记”

     

npm错误!有关此运行的完整日志,请参见:npm ERR!
  C:\ Users \ omare \ AppData \ Roaming \ npm-cache_logs \ 2018-07-30T09_21_21_147Z-debug.log

在日志文件中,我得到了:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'i',
1 verbose cli   'express' ]
2 info using npm@5.6.0
3 info using node@v8.11.3
4 verbose npm-session 1b65207ea7164d4e
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 304 https://registry.npmjs.org/express 1289ms (from cache)
8 silly fetchPackageMetaData error for express@^4.15.3 Unexpected end of JSON input while parsing near '..."hjs":"~0.0.6","marke'
9 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '..."hjs":"~0.0.6","marke'
9 verbose stack     at JSON.parse (<anonymous>)
9 verbose stack     at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\node_modules\json-parse-better-errors\index.js:7:17)
9 verbose stack     at consumeBody.call.then.buffer (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\src\body.js:96:50)
9 verbose stack     at <anonymous>
9 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
10 verbose cwd H:\Projects\WEB Development\My Stuff\Nuxt
11 verbose Windows_NT 10.0.17134
12 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" "express"
13 verbose node v8.11.3
14 verbose npm  v5.6.0
15 error Unexpected end of JSON input while parsing near '..."hjs":"~0.0.6","marke'
16 verbose exit [ 1, true ]

我的package.json文件:

{
  "name": "mevn",
  "version": "1.0.0",
  "description": "MongoDb, Express, Vue.js, and Node.js stack workflow",
  "main": "app.js",
  "scripts": {
    "start-server": "node server/bin/www",
    "dev": "webpack-dev-server --inline --progress --config Client/build/webpack.dev.conf.js",
    "start-client": "npm run dev",
    "build-client": "node Client/build/build.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Omar-Hussein/MEVN.git"
  },
  "keywords": [
    "workflow",
    "mevn",
    "mongodb",
    "express",
    "node",
    "vue"
  ],
  "author": "Omar Hussein",
  "license": "WTFPL",
  "bugs": {
    "url": "https://github.com/Omar-Hussein/MEVN/issues"
  },
  "homepage": "https://github.com/Omar-Hussein/MEVN#readme",
  "engines": {
    "node": ">= 6.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ],
  "dependencies": {
    "axios": "^0.18.0",
    "connect-mongo": "^2.0.1",
    "cors": "~2.8.4",
    "debug": "^3.1.0",
    "express-session": "^1.15.6",
    "express-validator": "^5.3.0",
    "http-errors": "^1.6.3",
    "lodash": "^4.17.10",
    "mongoose": "^5.2.5",
    "morgan": "^1.9.0",
    "vue": "^2.5.16",
    "vue-router": "^3.0.1",
    "vuetify": "^1.1.8",
    "vuex": "^3.0.1",
    "vuex-persistedstate": "^2.5.4",
    "vuex-router-sync": "^5.0.0"
  },
  "devDependencies": {
    "autoprefixer": "^9.0.1",
    "babel": "^6.23.0",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-loader": "^7.1.5",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-plugin-transform-vue-jsx": "^3.7.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-2": "^6.24.1",
    "chalk": "^2.4.1",
    "copy-webpack-plugin": "^4.5.2",
    "css-loader": "^1.0.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^1.1.11",
    "friendly-errors-webpack-plugin": "^1.7.0",
    "html-webpack-plugin": "^3.2.0",
    "material-design-icons-iconfont": "^3.0.3",
    "node-notifier": "^5.2.1",
    "optimize-css-assets-webpack-plugin": "^5.0.0",
    "ora": "^3.0.0",
    "portfinder": "^1.0.13",
    "postcss-import": "^11.1.0",
    "postcss-loader": "^2.1.6",
    "postcss-url": "^7.3.2",
    "rimraf": "^2.6.2",
    "semver": "^5.5.0",
    "shelljs": "^0.8.2",
    "uglifyjs-webpack-plugin": "^1.2.7",
    "url-loader": "^1.0.1",
    "vue-loader": "^15.2.6",
    "vue-style-loader": "^4.1.1",
    "vue-template-compiler": "^2.5.16",
    "webpack": "^4.16.3",
    "webpack-merge": "^4.1.3"
  }
}

信息:

      
  • 操作系统:Windows 10
  •   
  • 节点:v 8.11.3
  •   
  • NPM:v 5.6.0

某些模块我从以下位置得到此错误:

  • 表达
  • 连接闪存
  • webpack-bundle-analyzer
  • webpack-dev-server

2 个答案:

答案 0 :(得分:3)

尝试执行,

npm cache clean

然后做一个

npm install

希望这会有所帮助!

答案 1 :(得分:3)

在努力解决此问题后,最终对我有用的是

npm缓存清理--force

npm安装