admin管理员组

文章数量:1023773

To my big surprise the following trivial line:

export const PI = 3.14;

does not pile in Visual Studio Code and I am getting the following error:

(function (exports, require, module, __filename, __dirname) { export const PI = 3.14;                                                  

SyntaxError: Unexpected token export

Am I doing something wrong?

To my big surprise the following trivial line:

export const PI = 3.14;

does not pile in Visual Studio Code and I am getting the following error:

(function (exports, require, module, __filename, __dirname) { export const PI = 3.14;                                                  

SyntaxError: Unexpected token export

Am I doing something wrong?

Share Improve this question edited Apr 23, 2018 at 10:37 Unknown developer asked Apr 23, 2018 at 10:34 Unknown developerUnknown developer 5,97017 gold badges61 silver badges121 bronze badges 6
  • Could do you please explain what do you mean by is not running on Visual Studio Code – Hyyan Abo Fakher Commented Apr 23, 2018 at 10:36
  • @HyyanAboFakher he means the code doesnt pile – mast3rd3mon Commented Apr 23, 2018 at 10:37
  • Hmm , are you using the Code Runner Extension – Hyyan Abo Fakher Commented Apr 23, 2018 at 10:39
  • Code never really piles "in VS Code", it piles in some piler which is run by VS Code based on your configuration. You'll need to explain what piler settings you are using. – Quentin Commented Apr 23, 2018 at 10:39
  • Exactly, I am using Code Runner Extension – Unknown developer Commented Apr 23, 2018 at 10:40
 |  Show 1 more ment

2 Answers 2

Reset to default 4

You are using ES6 Module syntax.and node.js env which does not support ES6 Module syntax. NodeJS uses CommonJS Module syntax module.exports not ES6 module syntax export keyword.

Solutions:

  1. Use babel npm package to transpile your ES6 to a monjs target
  2. Refactor with CommonJS syntax.

To use ES6 Export module do you need add some transpiler to you project, if you don't want static type checker you can use Babel but if you want work with types in JS I remend you use TypeScript.

To my big surprise the following trivial line:

export const PI = 3.14;

does not pile in Visual Studio Code and I am getting the following error:

(function (exports, require, module, __filename, __dirname) { export const PI = 3.14;                                                  

SyntaxError: Unexpected token export

Am I doing something wrong?

To my big surprise the following trivial line:

export const PI = 3.14;

does not pile in Visual Studio Code and I am getting the following error:

(function (exports, require, module, __filename, __dirname) { export const PI = 3.14;                                                  

SyntaxError: Unexpected token export

Am I doing something wrong?

Share Improve this question edited Apr 23, 2018 at 10:37 Unknown developer asked Apr 23, 2018 at 10:34 Unknown developerUnknown developer 5,97017 gold badges61 silver badges121 bronze badges 6
  • Could do you please explain what do you mean by is not running on Visual Studio Code – Hyyan Abo Fakher Commented Apr 23, 2018 at 10:36
  • @HyyanAboFakher he means the code doesnt pile – mast3rd3mon Commented Apr 23, 2018 at 10:37
  • Hmm , are you using the Code Runner Extension – Hyyan Abo Fakher Commented Apr 23, 2018 at 10:39
  • Code never really piles "in VS Code", it piles in some piler which is run by VS Code based on your configuration. You'll need to explain what piler settings you are using. – Quentin Commented Apr 23, 2018 at 10:39
  • Exactly, I am using Code Runner Extension – Unknown developer Commented Apr 23, 2018 at 10:40
 |  Show 1 more ment

2 Answers 2

Reset to default 4

You are using ES6 Module syntax.and node.js env which does not support ES6 Module syntax. NodeJS uses CommonJS Module syntax module.exports not ES6 module syntax export keyword.

Solutions:

  1. Use babel npm package to transpile your ES6 to a monjs target
  2. Refactor with CommonJS syntax.

To use ES6 Export module do you need add some transpiler to you project, if you don't want static type checker you can use Babel but if you want work with types in JS I remend you use TypeScript.

本文标签: javascriptES6 modules in Visual Studio CodeStack Overflow