0

I have a simple project like this and have already install axios: The project

In main.js,I tried to import the axios and a json file but throw error:

import axios from 'axios' //SyntaxError: Cannot use import statement outside a module
import Test_data from 'json/test.json' //SyntaxError: Cannot use import statement outside a module

If I use require() it will success,could anybody tell me why?

var axios=require('axios');//success
var Test_data=require('./json/test.json');//success

console.log(Test_data);//success

1 Answers1

-2

Try to put attribute type=“module” into script element in index.html file.

<script src=“./main.js” type=“module”></script>
Nhan Hoang
  • 137
  • 2