为什么我在运行 npm run start 时总是收到这个错误?这是 React 的导入错误

时间:2021-03-13 16:14:41

标签: javascript reactjs npm

这是我的 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

我不知道为什么会出现此错误。我的剧本错了吗?还有其他问题吗?如果我删除节点,则会收到权限被拒绝错误。我不确定我是否应该在那里有节点。我很确定我是这样,我在这里真的很迷茫。我有哪些选择?

1 个答案:

答案 0 :(得分:0)

不久前我遇到了同样的问题,我无法 100% 记得我是如何摆脱它的,但我建议:

  1. 在 npm start 之前安装 npm(可能是 npm run setup)
  2. 确保您在运行 npm start 时位于正确的文件夹中