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
2023-08-28 20:10:06
<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>
type='module'
to thescript
tag to use theimport/export
syntaxbabel
,esbuild
, or your favorite compiler on the server, or typebabel
directly into HTML. You can also usevite