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 
2

1 Answer 1

-2

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

<script src=“./main.js” type=“module”></script> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.