Hi,
So I decided to switch to TypeScript today. In my revious node setup, I was using https://github.com/standard-things/esm for ESM import/export, as Node doesn't support it yet. When trying to run my start script with ts-node -r esm mrFox.ts, I get an error, like so:
import { token } from "./config.json";
^
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at Object.m._compile (/usr/lib/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.require.extensions.(anonymous function) [as .ts] (/usr/lib/node_modules/ts-node/src/index.ts:442:12)
This seems to be a result of esm not loading? not sure.
Please help, I would like to be able to use esm with node and ts-node.
In the README of that module it says you need to load it before ts-node.
It does? Where?

Given that you probably have to do something like node -r esm -r ts-node/register.
@blakeembrey your solution worked, thanks!
Given that you probably have to do something like
node -r esm -r ts-node/register.
For some reason, when i run this command more than once, i receive different results. First time is fine, but subsequent times require me to go to another branch and come back which seems very odd. Any suggestions?
Given that you probably have to do something like
node -r esm -r ts-node/register.For some reason, when i run this command more than once, i receive different results. First time is fine, but subsequent times require me to go to another branch and come back which seems very odd. Any suggestions?
I just needed to disable the cache as outlined in the options docs https://github.com/standard-things/esm#options
ESM_DISABLE_CACHE=true TS_NODE_PROJECT=scripts/tsconfig.json node -r esm -r ts-node/register scripts/index.ts
Most helpful comment
Given that you probably have to do something like
node -r esm -r ts-node/register.