Laravel 基础学习 Homestead 环境 NPM err 问题

laravel基础学习遇到问题

问题描述

  • 在执行 npm dev 时触发
    npm ERR! code EJSONPARSE
    npm ERR! file /home/vagrant/Code/weibo/package.json
    npm ERR! JSON.parse Failed to parse json
    npm ERR! JSON.parse Unexpected token / in JSON at position 853 while parsing near '...: "^4.0.0",
    npm ERR! JSON.parse         //"cross-env": "^5.1...'
    npm ERR! JSON.parse Failed to parse package.json data.
    npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/vagrant/.npm/_logs/2020-02-18T08_01_59_771Z-debug.log
    
    
  • 解决 项目 package.json 文件删除 cross-env 元素

    • 删除前

      {
      "private": true,
      "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": "npm run development -- --watch",
          "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"
      },
      "devDependencies": {
          "axios": "^0.19",
          "bootstrap": "^4.0.0",
          "cross-env": "^5.1",
          "jquery": "^3.2",
          "laravel-mix": "^5.0.1",
          "lodash": "^4.17.13",
          "popper.js": "^1.12",
          "resolve-url-loader": "^2.3.1",
          "sass": "^1.15.2",
          "sass-loader": "^8.0.0"
      }
      }
    • 删除后

      {
      "private": true,
      "scripts": {
          "dev": "npm run development",
          "development": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
          "watch": "npm run development -- --watch",
          "watch-poll": "npm run watch -- --watch-poll",
          "hot": "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": "NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
      },
      "devDependencies": {
          "axios": "^0.19",
          "bootstrap": "^4.0.0",
          "cross-env": "^5.1",
          "jquery": "^3.2",
          "laravel-mix": "^5.0.1",
          "lodash": "^4.17.13",
          "popper.js": "^1.12",
          "resolve-url-loader": "^2.3.1",
          "sass": "^1.15.2",
          "sass-loader": "^8.0.0"
      }
      }
      

后续报错

  • err内容

    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! @ development: `NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the @ development script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/vagrant/.npm/_logs/2020-02-18T08_52_20_990Z-debug.log
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! @ dev: `npm run development`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the @ dev script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/vagrant/.npm/_logs/2020-02-18T08_52_21_024Z-debug.log
  • 解决 执行命令

    npm install --no-bin-links

继续执行

npm run dev
npm run watch-poll

运行成功

 DONE  Compiled successfully in 18322ms  9:12:31 AM 
 Asset      Size   Chunks             Chunk Names
/css/app.css   178 KiB  /js/app  [emitted]  /js/app
  /js/app.js  1.06 MiB  /js/app  [emitted]  /js/app

参考链接

npm ERR! code ELIFECYCLE:Laravel 使用 NPM 遇到的问题
npm ERR! code EJSONPARSE :新手怎么解决 NPM run dev 报错的问题

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!