javascript Cannot use import statement outside a module when importing function from other file code example
Example 1: cannot use import statement outside a module typescript
// Fix 1
Change .js files to .cjs
// Fix 2
Add "type": "module" to package.json
Example 2: SyntaxError: Cannot use import statement outside a module
Node.js >= v13
Save the file with .mjs extension, &
Add { "type": "module" } in the nearest package.json.
(run npm init to create package.json)