简体   繁体   中英

facing issue in react js showing "Cannot use import statement outside a module"

import React from 'react';
import ReactDOM from 'react-dom';
import './Navigation';

ReactDOM.render(
  <React.StrictMode>
    <Navigation/>
  </React.StrictMode>,
  document.getElementById('root')
);

showing syntax error Cannot use import statement outside a module"

change import './Navigation'; to import Navigation from './Navigation';

if Navigation is not default export then change it to import { Navigation } from './Navigation';

If you are loading this file from your HTML you will need to set the type to module on the script tag.

Like: <script type="module" src="/path/to/file.js"></script">

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM