Getting Unexpected Token Export
I am trying to run some ES6 code in my project but I am getting an unexpected token export error.
export class MyClass {
constructor() {
console.log("es6");
}
}Updated for 2022 You are using EcmaScript Module (ESM or 'ES6 Modules') syntax but your environment does not support it. NodeJS versions prior to v14.13.0 do not support ESM (export keyword syntax) and use CommonJS Modules (module.exports property syntax). NodeJS v14.13.0 and newer supports ESM but it must be enabled first. Solutions: If you are using NodeJS v14.13.0 or newer (which does support ESM) you can enable it by setting "type":"module" in your project package.json Refactor with CommonJS Module syntax (for older versions of NodeJS) Consider using TypeScript alongside ts-node or ts-node-dev npm packages (for instant transpilation at development time) and write TypeScript in .ts files Transpile ESM to CommonJS using esbuild (esbuild package on npm) configured to transpile your ES6 javascript to a CommonJS target supported by your environment. (babel is no longer recommended)
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/8d4efacaaf08c750b28515e1ab1ea1c99afe76a94bdc1ed2523f760bd27a71a4