簡體   English   中英

為什么在運行 npm 運行啟動時總是出現此錯誤? 這是 React 的導入錯誤

[英]Why do I keep getting this error when running npm run start? It's an import error on React

這是我的 package.json

  "name": "airbnb",
  "version": "1.0.0",
  "description": "This is for my Project 2",
  "main": "index.js",
  "scripts": {
    "test": "None",
    "start": "node ./src/index.js"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "keywords": [
    "ReactJS",
    "ESLINT",
    "Prettier",
    "yapf"
  ],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "devDependencies": {
    "eslint": "^7.22.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-react": "^7.22.0",
    "eslint-plugin-react-hooks": "^4.2.0",
    "webpack-cli": "^4.5.0"
  },
  "dependencies": {
    "react": "^17.0.1",
    "socket.io-client": "^4.0.0"
  }
}

這是錯誤:

> airbnb@1.0.0 start /home/ec2-user/environment/flask_react_app/react-starter
> node ./src/index.js

/home/ec2-user/environment/flask_react_app/react-starter/src/index.js:1
import React from "react";
       ^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! airbnb@1.0.0 start: `node ./src/index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the airbnb@1.0.0 start 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/ec2-user/.npm/_logs/2021-03-13T15_44_38_370Z-debug.log

我不知道為什么我會收到這個錯誤。 我的腳本錯了嗎? 還有其他問題嗎? 如果我刪除節點,我會收到權限被拒絕錯誤。 我不確定我是否應該在那里有節點。 不過,我很確定我是,而且我在這里真的很迷茫。 我有什么選擇?

不久前我遇到了同樣的問題,我無法 100% 記得我是如何擺脫它的,但我建議:

  1. npm 安裝(可能是 npm 運行設置)在 npm 開始之前
  2. 確保在運行 npm start 時位於正確的文件夾中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM