cannot use import statement outside a module typescript 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: Uncaught SyntaxError: Cannot use import statement outside a module

1. Inside scripts file import the following module
	import {a} from "./module.js";
	alert(a);
    
2. add that script inside file you want to use it
	<script type="module" src="PATH_TO_FILE"></script>

Example 3: typescript mocha Cannot use import statement outside a module

"test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register 'src/test/**/*.ts'",

Tags:

Misc Example