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 projectpackage.json - Refactor with CommonJS Module syntax (for older versions of NodeJS)
- Consider using TypeScript alongside
ts-nodeorts-node-devnpm packages (for instant transpilation at development time) and write TypeScript in.tsfiles - Transpile ESM to CommonJS using esbuild (
esbuildpackage on npm) configured to transpile your ES6 javascript to a CommonJS target supported by your environment. (babel is no longer recommended)