Laravel 基礎學習 Homestead 環境 NPM err 問題

Bear_Brown發表於2020-02-18

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 協議》,轉載必須註明作者和本文連結

相關文章