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>
Top comments (0)