简体   繁体   English

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

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

whenever i try to make print it out on a browser i always get the error on the header "Uncaught SyntaxError: Cannot use import statement outside a module" before asking this question i tried all solutions similar to this problem including adding "type":"module", to my json package but none seems to work,i also added the "pack" and still no print out all my scripts are properly configured i use ecma6script and the latest version of react as well,每当我尝试在浏览器上打印它时,我总是在标题“Uncaught SyntaxError:无法在模块外使用导入语句”上出现错误,然后再问这个问题,我尝试了与此问题类似的所有解决方案,包括添加“类型”:”模块”,到我的 json 包但似乎没有工作,我还添加了“包”,但仍然没有打印出我的所有脚本都已正确配置我使用 ecma6script 和最新版本的 react,

here is my hmtl code below下面是我的 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"
    ]
  }
}```

You are trying to launch not compiled sources directly from a browser.您正在尝试直接从浏览器启动未编译的源代码。 To launch a workable app you can do:要启动一个可行的应用程序,您可以执行以下操作:

  1. npm start - DEV server launched on localhost:3000 npm start - 在 localhost:3000 上npm start DEV 服务器
  2. npm run build - PROD build, compiles the sources into the build/ folder. npm run build - PROD 构建,将源代码编译到build/文件夹中。 There you'll find compiled JS, CSS and index.html to launch.在那里你会找到编译好的 JS、CSS 和 index.html 来启动。

暂无
暂无

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

相关问题 未捕获的语法错误:无法在 React 模块外使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module for React 如何解决“未捕获的语法错误:无法在模块外使用导入语句”? - How to resolve “Uncaught SyntaxError: Cannot use import statement outside a module”? 未捕获的语法错误:无法在模块外使用 import 语句 - Uncaught SyntaxError : Cannot use import statement outside a module 未捕获的语法错误:无法在模块外使用导入语句 - Uncaught SyntaxError:Cannot use import statement outside a module 未捕获的语法错误:无法在模块外使用 import 语句 - Uncaught SyntaxError: Cannot use import statement outside a module 未捕获的语法错误:无法在模块外使用导入语句 - Javascript - Uncaught SyntaxError: Cannot use import statement outside a module - Javascript 未捕获的语法错误:无法在节点 js 中的模块外使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module in node js 未捕获的语法错误:无法在具有 OpenLayers 的模块外部使用 import 语句 - Uncaught SyntaxError: Cannot use import statement outside a module with OpenLayers JS:未捕获的语法错误:无法在模块外使用导入语句 - JS : Uncaught SyntaxError: Cannot use import statement outside a module 未捕获的语法错误:无法在模块外使用导入语句(使用 Firebase) - Uncaught SyntaxError: Cannot use import statement outside a module (Using Firebase)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM