You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using ts-node as part of Serverless to read the serverless.ts configuration file in my project which is defined as ESM with "type": "module" in package.json and "esm": true in tsconfig.json.
Same behavior like NODE_OPTIONS="--loader ts-node/esm".
Actual Behavior
If I start the serverless CLI with NODE_OPTIONS="--loader ts-node/esm", it loads the serverless.ts without a problem. However, if I avoid the NODE_OPTIONS env, I get the following error:
ts-node is used programmatically and registered as require(tsNodePath).register(); and I can verify that the tsNodePath points to a locally installed package. Somehow, when it then comes to the following await import('serverless.ts') it crashes with this error.
Node does not give us any way to programmatically register the ESM hooks at runtime. If you're curious to learn more, check out node's docs for --loader.
Seems like you do have a working solution with NODE_OPTIONS. As na alternative, some projects choose to write their config as CommonJS, and there are various options for doing that in an otherwise ESM project.
Search Terms
ESM
NODE_OPTIONS
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
Expected Behavior
I'm using ts-node as part of Serverless to read the
serverless.ts
configuration file in my project which is defined as ESM with"type": "module"
in package.json and"esm": true
in tsconfig.json.Same behavior like
NODE_OPTIONS="--loader ts-node/esm"
.Actual Behavior
If I start the serverless CLI with
NODE_OPTIONS="--loader ts-node/esm"
, it loads theserverless.ts
without a problem. However, if I avoid theNODE_OPTIONS
env, I get the following error:ts-node is used programmatically and registered as
require(tsNodePath).register();
and I can verify that thetsNodePath
points to a locally installed package. Somehow, when it then comes to the followingawait import('serverless.ts')
it crashes with this error.Steps to reproduce the problem
Minimal reproduction
See repo: https://github.com/zirkelc/serverless-esm-test
Steps to reproduce:
throws error
ERR_UNKNOWN_FILE_EXTENSION]
no error
Specifications
ts-node v10.8.1
node v16.13.0
compiler v4.7.3
macOS
The text was updated successfully, but these errors were encountered: