繁体   English   中英

REACT-APP 未捕获的语法错误:无法在模块外使用导入语句

[英]REACT-APP Uncaught SyntaxError: Cannot use import statement outside a module

每当我尝试在浏览器上打印它时,我总是在标题“Uncaught SyntaxError:无法在模块外使用导入语句”上出现错误,然后再问这个问题,我尝试了与此问题类似的所有解决方案,包括添加“类型”:”模块”,到我的 json 包但似乎没有工作,我还添加了“包”,但仍然没有打印出我的所有脚本都已正确配置我使用 ecma6script 和最新版本的 react,

下面是我的 hmtl 代码

    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div id="root"></div>
        <script src="indexx.js"></script>
    </body>
</html>```

and here is my reactcode

```import React from "react";
import ReactDom from "react-dom";

ReactDom.render(<h1>hello world</h1>, document.getElementById("root"));```


  below is my json package

```{
  "name": "asa-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.5",
    "@testing-library/react": "^11.1.1",
    "@testing-library/user-event": "^12.2.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.0",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
    
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}```

您正在尝试直接从浏览器启动未编译的源代码。 要启动一个可行的应用程序,您可以执行以下操作:

  1. npm start - 在 localhost:3000 上npm start DEV 服务器
  2. npm run build - PROD 构建,将源代码编译到build/文件夹中。 在那里你会找到编译好的 JS、CSS 和 index.html 来启动。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM