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,
here is my hmtl code below
<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:
npm start
- DEV server launched on localhost:3000 npm run build
- PROD build, compiles the sources into the build/
folder. There you'll find compiled JS, CSS and index.html to launch.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.