nodejs react:在命令纱线构建时,package.json文件中的构建脚本无法正常工作

时间:2018-03-12 21:59:35

标签: webpack-2

在我对package.json进行以下编辑后运行yarn build命令时,在linux和windows上都有:

{  
"name": "chatastrophe",  
"version": "1.0.0", 
 "main": "index.js",
  "license": "MIT", 
 "scripts": {  
  "build": "node_modules/.bin/webpack",
'  }, 
 "dependencies": {   
 "react": "15.6.1",  
  "react-dom": "15.6.1", 
   "webpack": "3.5.4",
  } 
}

我一直收到这个错误:

  

错误发生意外错误:   “C:\ Users \ Richard \ Desktop \ chatastrophe \ package.json:意外   在位置175的JSON中的标记} .info如果你认为这是一个bug,   请使用提供的信息打开错误报告   “C:\用户\理查德\桌面\ chatastrophe \纱线error.log中”

此错误的更详细版本如下(当我使用npm而不是纱线时)

npm ERR! file C:\Users\Richard\Desktop\chatastrophe\package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected token } in JSON at position 175 while parsing near '...webpack",
npm ERR!           },
npm ERR!         "dependen...'
npm ERR! File: C:\Users\Richard\Desktop\chatastrophe\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! Tell the package author to fix their package.json file. JSON.parse

任何人都可以帮助我。提前谢谢。

4 个答案:

答案 0 :(得分:2)

谢谢,它有点工作,直到我必须运行webpack开发服务器...我收到此错误:lelo @ lelo-Latitude-E6220:〜/ Desktop / chatastrophe $ npm run start

  

chatastrophe@1.0.0 start / home / lelo / Desktop / chatastrophe   的WebPack-DEV-服务器

/home/lelo/Desktop/chatastrophe/node_modules/ajv-keywords/keywords/instanceof.js:52     抛出新错误(“无效”实例“关键字值”+ c);     ^

错误:无效的“instanceof”关键字值Promise     at getConstructor(/home/lelo/Desktop/chatastrophe/node_modules/ajv-keywords/keywords/instanceof.js:52:11)     在Ajv.compile(/home/lelo/Desktop/chatastrophe/node_modules/ajv-keywords/keywords/instanceof.js:21:27)     at Object.useCustomRule(/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/compile/index.js:275:26)     在Object.generate_custom [作为代码](/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/dotjs/custom.js:32:24)     at Object.generate_validate [as validate](/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/dotjs/validate.js:347:35)     at Object.generate_anyOf [as code](/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/dotjs/anyOf.js:34:27)     at generate_validate(/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/dotjs/validate.js:347:35)     在localCompile(/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/compile/index.js:87:22)     在Ajv.compile(/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/compile/index.js:56:13)     在Ajv._compile(/home/lelo/Desktop/chatastrophe/node_modules/ajv/lib/ajv.js:358:27) 错误的ERR!代码ELIFECYCLE 错误的ERR!错误1 错误的ERR! chatastrophe@1.0.0 start:webpack-dev-server 错误的ERR!退出状态1 错误的ERR! 错误的ERR!在chatastrophe@1.0.0启动脚本失败。 错误的ERR!这可能不是npm的问题。上面可能有额外的日志记录输出。

答案 1 :(得分:1)

你的package.json构建脚本是无效的JSON,是逗号后面的单引号。试试这个:

kill PID

答案 2 :(得分:0)

"scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },

答案 3 :(得分:0)

解决方案是更新我的package.json文件,使其包括以下脚本和依赖项:

    "build": "node scripts/copy_assets.js && node_modules/.bin/webpack --config webpack.config.prod.js",
    "start": "node_modules/.bin/webpack-dev-server",
    "deploy": "npm run build && firebase deploy"
  },
  "dependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.4",
    "file-loader": "^0.11.2",
    "fs-extra": "^4.0.1",
    "html-webpack-plugin": "^2.30.1",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-hot-loader": "3.0.0",
    "react-router-dom": "^4.2.2",
    "style-loader": "^0.18.2",
    "webpack": "^3.5.4",
    "webpack-dev-server": "^2.7.1",
    "webpack-manifest-plugin": "^1.3.1"
  },
  "devDependencies": {
    "babel-preset-stage-2": "^6.24.1"
  }
}