Welcome

)}exportdefaultGreet//This is indx.js file importReact,{Component} from'react'importGreetfrom'."> 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-PHP Chinese Network Q&A
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
556

//This is the greet.js file

import React from "react"; functionGreet() { return ( 

Welcome

) } export default Greet

//This is the indx.js file

import React,{Component} from 'react' import Greet from './Greet' class App extends Component { render() { 
} }

//This is an html file

    Here We Go  

I'm trying to get data from greet.js and render it in indx.js, but I get the Cannot use import statement outside module error

P粉520545753
P粉520545753

reply all (1)
P粉885035114
  • The reason you are getting the error is because you need to addtype='module'to thescripttag to use theimport/exportsyntax
  • You cannot use JSX in the browser. You can usebabel,esbuild, or your favorite compiler on the server, or typebabeldirectly into HTML. You can also usevite
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!