0

The import is not working.

// 
...

var data1 ="";

...

axios.post(BASE_URL + '/filename')
.then(res => 
{
    data1 = res.data;
    console.log(`This is the data we need :`+data1);
    import data from (`./files/`+ data1);

})
//

I imported the data file but i want it to be able to change file name. Now it does not work. Any solutions ?

Haziman Hamzil
  • 75
  • 1
  • 12
  • Any errors? What exactly does not work? – Justinas Apr 15 '19 at 07:07
  • Line 52: Parsing error: 'import' and 'export' may only appear at the top level – Haziman Hamzil Apr 15 '19 at 07:09
  • move import to top – 1565986223 Apr 15 '19 at 07:11
  • If i put the import to the top, i will get this error : Line 6: Parsing error: Unexpected token Which it shows at data1 – Haziman Hamzil Apr 15 '19 at 07:13
  • 3
    Possible duplicate of [ES6: Conditional & Dynamic Import Statements](https://stackoverflow.com/questions/35914712/es6-conditional-dynamic-import-statements) – jonrsharpe Apr 15 '19 at 07:14
  • axios.post(BASE_URL + '/filename') .then(res => { data1 = res.data; console.log(`This is the data we need :`+data1); import(`../files/`+ data1) .then((data1) => {console.log(data1.data1);}); }) The error come out by taking all my files in the console. SyntaxError: Unexpected end of JSON input while parsing near '' – Haziman Hamzil Apr 15 '19 at 07:37

0 Answers0