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 typescript

// Fix 1
Change .js files to .cjs
// Fix 2
Add "type": "module" to package.json
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 make link in discord.js 
Javascript :: javascript random number generator 
Javascript :: how to send query parameters in url vuejs 
Javascript :: js array of objects get a specific key from all objects 
Javascript :: javascript string to lowercase 
Javascript :: react forms 
Javascript :: axios post 
Javascript :: camelcase to normal text javascript 
Javascript :: set background color dynamically javascript 
Javascript :: react usestate functional update 
Javascript :: how to run function after animation complete jquery 
Javascript :: Sort big numbers from an array in javascript 
Javascript :: How to get the Class Name of an Object in JavaScript 
Javascript :: e.target.text react 
Javascript :: javascript two digit number 
Javascript :: jquery confirmation dialog example 
Javascript :: remove duplicated from array of ojects 
Javascript :: change next js default port 
Javascript :: react app js 
Javascript :: js capitalize word 
Javascript :: array to object 
Javascript :: confirm javascript 
Javascript :: nodejs event 
Javascript :: json dummy data 
Javascript :: shuffle array item javascruitp 
Javascript :: get object with max value javascript 
Javascript :: npm react copy to clipboard 
Javascript :: javascript string to variable 
Javascript :: input type number maxlength in react 
Javascript :: javascript random element from array 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =