Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

SyntaxError: Cannot use import statement outside a module

// 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!)
 
PREVIOUS NEXT
Tagged: #Cannot #import #statement #module
ADD COMMENT
Topic
Name
3+9 =