[英]Uncaught SyntaxError: Cannot use import statement outside a module for React
[英]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"
]
}
}```
您正在嘗試直接從瀏覽器啟動未編譯的源代碼。 要啟動一個可行的應用程序,您可以執行以下操作:
npm start
- 在 localhost:3000 上npm start
DEV 服務器npm run build
- PROD 構建,將源代碼編譯到build/
文件夾中。 在那里你會找到編譯好的 JS、CSS 和 index.html 來啟動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.