Skip to content
Advertisement

“Uncaught SyntaxError: Cannot use import statement outside a module” When Importing ReactJS

Today I decided to try to learn React, but whenever I try to import the two modules below:

import React from "react"
import ReactDOM from "react-dom"

I get the error:

Uncaught SyntaxError: Cannot use import statement outside a module

Here’s the steps I’ve taken to try to create my React program:

  1. Install NodeJS
  2. Add NodeJS to environmental variables
  3. Create new folder for my program
  4. Create HTML, CSS, and JS files in my folder

Why am I getting this error, and how can I fix it?

Advertisement

Answer

I assume this is your first time working with React? I see that you have installed NodeJs, which is great!

I recommend that you get started with a complete React app such as Create React App.

https://create-react-app.dev/

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement