// SOLUTION 1:
// in package.json add:
{
"type": "module"
}
// in my case package.json file looks like this now:
{
"type": "module",
"dependencies": {
"colors": "^1.4.0"
}
}
// SOLUTION 2:
// instead of
import myPackage from "myPackage"
// use
const myPackage = require("myPackage")
// BOOM! Problem solved (if not I wish you luck!)
//make sure whether include type="module" in script tag
<script type="module" src="module.js"></script>
//Add type=module to your index.js script tag (not just the package script tag)
<script type="module" src="./index.js"></script>
{
// ...
"type": "module",
// ...
}
<script type="module" src="some_script.js"></script>
package.json
{
// ...
"type": "module",
// ...
}
ts.config updated
"target": "esnext",
"module": "commonjs",
<script src="../src/main.js"></script>