2 Quick and Easy Ways to Fix 'Uncaught SyntaxError: Cannot use import statement outside a module'by@smpnjn
6,363 reads

2 Quick and Easy Ways to Fix 'Uncaught SyntaxError: Cannot use import statement outside a module'

August 8th 2022
2 min
by @smpnjn 6,363 reads
tldt arrow
Read on Terminal Reader🖨️

Too Long; Didn't Read

Node.js error: Cannot use import statement outside a module. This error arises when we try to use `import` inside of a project which is not set up for modules. The reason why this error occurs is because we have to explicitly tell Javascript that the file in question is a `module` The error can be resolved in two ways: updating your package.json and changing the file extension to 'mjs' The second place this error can occur is in a script tag, like this: Add 'type="my module" to your script tag.

Company Mentioned

Mention Thumbnail
featured image - 2 Quick and Easy Ways to Fix 'Uncaught SyntaxError: Cannot use import statement outside a module'
Johnny Simpson HackerNoon profile picture

@smpnjn

Johnny Simpson

About @smpnjn
LEARN MORE ABOUT @SMPNJN'S EXPERTISE AND PLACE ON THE INTERNET.
react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!
Hackernoon hq - po box 2206, edwards, colorado 81632, usa