HOW TO FIX SyntaxError: Cannot use import statement outside a module
Are you using imports in a node.js application and running into the SyntaxError: Cannot use import statement outside a module error? Here are 3 ways to fix this error. If you're developing a JavaScript application, then add "type": "module" into your package.json file. If you're developing a TypeScript application, then make sure "module" is set to "commonjs" in your tsconfig.json file. If you're importing a script in a HTML file, then add type="module" into the script tag.
Are you using imports in a node.js application and running into the SyntaxError: Cannot use import statement outside a module error? Here are 3 ways to fix this error. If you're developing a JavaScript application, then add "type": "module" into your package.json file. If you're developing a TypeScript application, then make sure "module" is set to "commonjs" in your tsconfig.json file. If you're importing a script in a HTML file, then add type="module" into the script tag.