standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

Cannot use class field #800

Closed chungchi300 closed 5 years ago

chungchi300 commented 5 years ago

https://github.com/tc39/proposal-class-fields

jdalton commented 5 years ago

Hi @chungchi300!

We support parsing class fields. However, the Node version you use must support them.

chungchi300 commented 5 years ago

I mean does it support ESnext Class Fields? The class fields proposal allows properties to be initialized at the top of a class:

class MyClass {

  a = 1;
  b = 2;
  c = 3;

}
jdalton commented 5 years ago

The esm loader supports whatever functionality native Node does. You can get class fields in Node 12 or --harmony I believe.

dnalborczyk commented 5 years ago

@chungchi300 could you verify your node version?

either run node --version in the terminal, or check process.versions.node in your node app. if it's not at least v12.0, you have to either run node.js with the --harmony flag, as @jdalton suggested, or use a transpiler, like Babel.

if your node version is v12.x, and you are still running into this issue, could you provide some repro steps, or better, create a small repository?