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

Time:01-02

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"

CodePudding user response:

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

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

CodePudding user response:

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">

  • Related