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

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

August 8th 2022
2m
by @smpnjn 14,496 reads
tldt arrow
Read on Terminal Reader
Read this story w/o Javascript

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

Product, Engineering, Web


Receive Stories from @smpnjn

react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!