import & require
ChuangWANG
Posted on April 30, 2021
fix: SyntaxError: Cannot use import statement outside a module
Follow is ok.
let test = require('mathjs')
let result = test.round(3.12484, 3)
console.log(result)
But import syntax is error:
import { round } from 'mathjs'
let test = round(3.1515,2)
console.log(test)
Solution :
In your package.json file, simply add “type”:“module” to fix this issue :
Or you can add the below line in your main entry JS file:
<script type="module" src="main.js"></script>
💖 💪 🙅 🚩
ChuangWANG
Posted on April 30, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024