0

I want to import data to Javascript.js from Export.js. But im getting Unexpected token error.

Error : enter image description here

This is my Export.js file

export const expData = [1,2,3];

This is my Javascript.js file

import { expData } from './Export.js';
console.log(expData);

There is no html code on it, I just run it on Terminal. Please help me if you guys have any solutions. Thanks.

Kai
  • 155
  • 3
  • 9
  • What's the error message it shows? – Murali Nepalli May 07 '19 at 03:28
  • 1
    A couple of things to try. Depending on the environment (node or browser), it may not understand ES6 code. If you try plain old `require` and it works, then you know it is an issue with the environment understanding ES6 code. https://stackoverflow.com/questions/46306148/chrome-61-unexpected-token-import https://stackoverflow.com/questions/41722621/es6-in-the-browser-uncaught-syntaxerror-unexpected-token-import – snewcomer May 07 '19 at 03:31
  • @snewcomer I didn't run it on Chrome or Firefox. I only run it on Visual Studio code Terminal. – Kai May 07 '19 at 03:47
  • @MuraliNepalli question updated lol – Kai May 07 '19 at 03:47
  • I suspect your setup does not support ES2015 or greater. Do you have reason to think that such features would be supported? What happens when you comment out the `import` and use other modern features, like your `const expData` declaration? – Jake Worth May 07 '19 at 03:59
  • @JakeWorth you mean declare const expData and Console.Log(expData) on the same .js file ? If is that then it work fine actually, just that import export have error. – Kai May 07 '19 at 04:11
  • @Kai thanks for looking into that. I still think the issue here is lack of ES2015/6+ support. – Jake Worth May 07 '19 at 14:35

0 Answers0