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 :: javascript how to get rid of e with number input 
Javascript :: how to target an element inside of a $(this) jquery 
Javascript :: accessing objects inside array 
Javascript :: Prevent default event behavior 
Javascript :: css variable value changing with javascript 
Javascript :: how to convert draftjs content to html 
Javascript :: scrollintoview javascript 
Javascript :: indexof javascript duplicate arrays 
Javascript :: empty check on django json field 
Javascript :: get file extension file upload control in javascript 
Javascript :: multiple styles in react native 
Javascript :: change image onclick javascript 
Javascript :: funciones invocan a funciones javascript 
Javascript :: startswith vowels in js 
Javascript :: how to make page scroll to the top jsx 
Javascript :: Vue JS Production mode refresh causing 404 error 
Javascript :: javascript on scroll change nav color 
Javascript :: select2 replace options 
Javascript :: javaScript Math.log2() Method 
Javascript :: node powershell 
Javascript :: find max number in java 
Javascript :: class component react 
Javascript :: javascript on enter key searchbox 
Javascript :: convert html to pdf using javascript 
Javascript :: react button onclick components 
Javascript :: Prevent safari loading from cache when back button is clicked 
Javascript :: window location any web 
Javascript :: convert days in years js 
Javascript :: nuxt auth keep user loggedin on refresh 
Javascript :: javascript unicode to string 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =