To load an ES module, set "type": "module" in the package.json or use the .mjs extension

setting "type": "module" in your package.json should work. Check again if you made an error in inputting it. Solved my problem when I inputted it.


Using the following command worked for me with node v14.16.1:

node --loader ts-node/esm --experimental-specifier-resolution=node index.ts

There is a warning telling me that --experimental-loader is an experimental feature but I don't care because I only use it to debug the typescript code.