首页 > 解决方案 > 在执行“npm install”时,它显示“在 '...FFso8TBG3jS7\nYdtExKk' 附近解析时 JSON 输入意外结束”

问题描述

所以,我正在尝试通过官方指南(https://codelabs.developers.google.com/codelabs/tensorflowjs-nodejs-codelab/#2)做一些 TensorFLow。我已经下载了 package.json 和 webpack.config.js。

pacakage.json 如下:

    {
  "name": "tfjs-examples-baseball-node",
  "version": "0.2.0",
  "description": "Deep learning models for classifying baseball metrics",
  "scripts": {
    "start-client": "webpack && webpack-dev-server",
    "start-server": "node server.js"
  },
  "license": "Apache-2.0",
  "devDependencies": {
    "clang-format": "~1.2.3",
    "mkdirp": "~0.5.1",
    "webpack": "~4.28.4",
    "webpack-cli": "^3.3.2",
    "webpack-dev-server": "~3.4.1"
  },
  "dependencies": {
    "@tensorflow/tfjs-node": "^1.3.2",
    "argparse": "^1.0.10",
    "socket.io": "~2.2.0"
  }
}

webpack.congig.js 看起来像这样:

const path = require('path');

module.exports = {
    entry: './client.js',
    output: {path: path.resolve(__dirname, 'dist'), filename: 'bundle.js'},
    devServer: {
        historyApiFallback: true,
        noInfo: true,
        host: '0.0.0.0',
        disableHostCheck: true
    }
};

当我运行“npm install”时。它安装了一些东西,但不是所有东西,并给出了以下错误:

npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated 
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated 
npm ERR! Unexpected end of JSON input while parsing near '...FFso8TBG3jS7\nYdtExKk'

我已经尝试过npm cache clear --force,但它仍然无法正常工作。我试过npm install -g了,它显然安装了所有依赖项,但只安装了 dev-dependencies 中的 mkdirp ,而其他所有依赖项都被卸载了。

有人可以建议尝试一下吗?

标签: javascriptnode.jstensorflownpm

解决方案


对于 Mac 操作系统用户,

  1. 首先运行“npm cache clean --force”
  2. 然后运行“npm i”

推荐阅读