ts-node: ts-node and ts-node-dev don't work with `cannot read property of undefined` for everything locally imported.

But tsc && node -r esm . and nodemon -e ts -x 'tsc && node -r esm .' works OK.

Everything that I locally imported seems to be undefined with ts-node and I have tried madge and detect-circular-deps and they could not find a problem…

Real project – https://github.com/patarapolw/rep2recall-web/blob/91e6f6a5870dca52010b4e569d4bb81f7c5be78f/package.json#L92 and https://github.com/patarapolw/rep2recall-web/blob/master/src/backend/server.ts

https://stackoverflow.com/questions/55753635/ts-node-and-ts-node-dev-dont-work-with-cannot-read-property-of-undefined-and

Might be exactly the same issue as https://github.com/TypeStrong/ts-node/issues/819

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18

Most upvoted comments

@cspotcode I tried also the same scenario without the package.json field type set to module and removed the esm requirement,

  1. Without esm and module set to esnext. Errors out since it can’t understand import statements
  2. Without esm and module set to commonjs. Returns the value as expected with or without the path mappings.

If we get a minimal reproduction, we can identify the root cause.