Моя версия узла - v8.11.3, я просто создаю простой класс и запускаю его с помощью следующей команды.
тест узла --harmony-async-await
test.js
import * as moment from 'moment';
class test {
web;
async getToken(symbol) {
return symbol;
}
}
выдает ошибку в переменной сеть и импортирует
import * as moment from 'moment';
^^^^^^
web;
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
как это решить?
redefine js to mjs
а также
node test --harmony-async-await --experimental-modules
все еще не работает
npm install -g es-checker
es-checker
ECMAScript 6 Feature Detection (v1.4.1)
Variables
√ let and const
√ TDZ error for too-early access of let or const declarations
√ Redefinition of const declarations not allowed
√ destructuring assignments/declarations for arrays and objects
√ ... operator
Data Types
√ For...of loop
√ Map, Set, WeakMap, WeakSet
√ Symbol
√ Symbols cannot be implicitly coerced
Number
√ Octal (e.g. 0o1 ) and binary (e.g. 0b10 ) literal forms
√ Old octal literal invalid now (e.g. 01 )
√ Static functions added to Math (e.g. Math.hypot(), Math.acosh(), Math.imul() )
√ Static functions added to Number (Number.isNaN(), Number.isInteger() )
String
√ Methods added to String.prototype (String.prototype.includes(), String.prototype.repeat() )
√ Unicode code-point escape form in string literals (e.g. \u{20BB7} )
√ Unicode code-point escape form in identifier names (e.g. var \u{20BB7} = 42; )
√ Unicode code-point escape form in regular expressions (e.g. var regexp = /\u{20BB7}/u; )
√ y flag for sticky regular expressions (e.g. /b/y )
√ Template String Literals
Function
√ arrow function
√ default function parameter values
√ destructuring for function parameters
√ Inferences for function name property for anonymous functions
× Tail-call optimization for function calls and recursion
Array
× Methods added to Array.prototype ([].fill(), [].find(), [].findIndex(), [].entries(), [].keys(), [].values() )
√ Static functions added to Array (Array.from(), Array.of() )
√ TypedArrays like Uint8Array, ArrayBuffer, Int8Array(), Int32Array(), Float64Array()
√ Some Array methods (e.g. Int8Array.prototype.slice(), Int8Array.prototype.join(), Int8Array.prototype.forEach() ) added to the TypedArray prototypes
√ Some Array statics (e.g. Uint32Array.from(), Uint32Array.of() ) added to the TypedArray constructors
Object
√ __proto__ in object literal definition sets [[Prototype]] link
√ Static functions added to Object (Object.getOwnPropertySymbols(), Object.assign() )
√ Object Literal Computed Property
√ Object Literal Property Shorthands
√ Proxies
√ Reflect
Generator and Promise
√ Generator function
√ Promises
Class
√ Class
√ super allowed in object methods
√ class ABC extends Array { .. }
Module
× Module export command
× Module import command
=========================================
Passes 38 feature Detections
Your runtime supports 90% of ECMAScript 6
=========================================
как я могу получить 100% поддержку, особенно по экспорту и импорту
Возможный дубликат Модуль импорта nodejs 8 - требовать или импортировать?
Я не могу использовать экспорт, импорт, общедоступный или определить какую-либо переменную класса, я вижу ваше сообщение, но не нашел решения для этого
Что именно должен делать web;? Это должно быть поле класса? Если да, то это невозможно с JavaScript еще.
Я использую последнюю версию узла, но все еще не работаю
Вы должны быть более конкретными, чем «не работает».
я не могу использовать импорт или экспорт, например, import * as moment from 'moment'; Я могу определить класс test {}, но наличие общедоступной / частной переменной в классе не позволяет компилировать.





Я не думаю, что способ объявления класса семантически верен. Не очевидно, что вы пытаетесь сделать с веб-переменной.