2

I am getting this error when running a javascript file from inside using code runner.

(function (exports, require, module, __filename, __dirname) { import Vue from 'vue'
                                                                 ^^^

SyntaxError: Unexpected identifier

I do have a jsconfig.json file in the root of my project directory which includes

{
"compilerOptions": {
    "target": "es6"
}

}

and my code runner configuration is simply

"code-runner.executorMap": {
    "javascript": "node --no-warnings"
}

The only line of code in the test script is import Vue from 'vue'

How can i use es6 imports in vscode?

SSteve
  • 10,550
  • 5
  • 46
  • 72
securisec
  • 3,435
  • 6
  • 36
  • 63
  • Do you have a html file in your project? – Stephan T. Jan 09 '19 at 06:34
  • No i dont have an html file. Why would that make a difference? The same error fires no matter what module i am using – securisec Jan 09 '19 at 06:36
  • You get this error if your script tag doesn't have "type: module" defined in your html – Stephan T. Jan 09 '19 at 06:38
  • No, I think you might be incorrect on this one. This question isnt about how to use es6 imports on the browser, it is about using es6 imports inside vscode. as the problem states, the error doesnt fire when running the file directly with node on the terminal. it only fires when running it from inside vscode – securisec Jan 09 '19 at 06:39
  • You were right of course, totally different problem, i found your exact proplem on github right after the article i read about the html problem – Stephan T. Jan 09 '19 at 06:49

1 Answers1

0

Take a look at this issue on GitHub. That issue references the solution to your problem. You probably have to use babel-register:

1:

$ npm i -D babel-register

2:

$ npm i -D babel-preset-es2015

3: config babel in package.json

{
  // ...
  // something else
  // ...
  "devDependencies": {
    "babel-preset-es2015": "^6.18.0",
    "babel-register": "^6.18.0"
  },
  "babel": {
    "presets": [
      "es2015"
    ],
    "sourceMaps": true,
    "retainLines": true
  }
}
Stephan T.
  • 5,843
  • 3
  • 20
  • 42
  • 1
    I have seen this article before posting here. This article is about debugging the code. The proposed solution does not make the error go away. It is still the same error – securisec Jan 09 '19 at 06:58