Search
 
SCRIPT & CODE EXAMPLE
 

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!)
Comment

Cannot use import statement outside a module (at module.js:1:1)


//make sure whether include type="module" in script tag
<script type="module" src="module.js"></script>
Comment

cannot use import statement outside a module

//Add type=module to your index.js script tag (not just the package script tag)

<script type="module" src="./index.js"></script>
Comment

Uncaught SyntaxError: cannot use import statement outside a module

{
        // ...
        "type": "module",
        // ...
    }
Comment

cannot use import statement outside a module

<script type="module" src="some_script.js"></script>
Comment

cannot use import statement outside a module

package.json
   {
        // ...
        "type": "module",
        // ...
    }
Comment

Uncaught SyntaxError: cannot use import statement outside a module

ts.config updated
    "target": "esnext",
    "module": "commonjs",
Comment

cannot use import statement outside a module

<script src="../src/main.js"></script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add attribute to selected element in javascript 
Javascript :: set cookie javascript 
Javascript :: create link and click javascript 
Javascript :: js get locale 
Javascript :: try catch in javascript 
Javascript :: sum an array in javascript 
Javascript :: website link regex stackoverflow 
Javascript :: dynamics js search another entity 
Javascript :: redis json get multiple paths 
Javascript :: javascript function description standards 
Javascript :: hiding header in a specific screen in react native 
Javascript :: nodejs tcp client 
Javascript :: js add seconds to current time 
Javascript :: Remove all child nodes of a list: 
Javascript :: js getattribute 
Javascript :: select all checkboxes jquery 
Javascript :: colors.xml" already exists! 
Javascript :: how to remove element from array react native 
Javascript :: how to make 1st letter capital in ejs 
Javascript :: javascript change border radius 
Javascript :: find missing number array javascript 
Javascript :: React modal input field auto focus antd 
Javascript :: match url regex 
Javascript :: express serve static files 
Javascript :: stopped typing jquery 
Javascript :: get message by id discord.js 
Javascript :: index.js vs main.js 
Javascript :: style after javascript 
Javascript :: get value of element html js 
Javascript :: java script cosinus grad 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =