Rewrite the title to: Translate "SyntaxError: Cannot use import statement outside a module" into Chinese as "SyntaxError: Cannot use import statement outside a module" when running on the live server
P粉520545753
P粉520545753 2023-08-28 20:10:06
0
1
634
<p>//This is the greet.js file</p> <pre class="brush:php;toolbar:false;">import React from "react"; functionGreet() { return ( <div><h1>Welcome</h1></div> ) } export default Greet</pre> <p>//This is the indx.js file</p> <pre class="brush:php;toolbar:false;">import React,{Component} from 'react' import Greet from './Greet' class App extends Component { render() { <div className='App'> <Greet/> </div> } }</pre> <p>//This is an html file</p> <pre class="brush:php;toolbar:false;"><!DOCTYPE html> <html> <head> <title> Here We Go </title> </head> <body> <script src="indx.js"> </script> </body> </html></pre> <p>I'm trying to get data from greet.js and render it in indx.js, but I get the <strong>Cannot use import statement outside module error</strong></p>
P粉520545753
P粉520545753

reply all(1)
P粉885035114
  • The reason you are getting the error is because you need to add type='module' to the script tag to use the import/export syntax
  • You cannot use JSX in the browser. You can use babel, esbuild, or your favorite compiler on the server, or type babel directly into HTML. You can also use vite
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template