New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ts-node and ts-node-dev don't work with cannot read property of undefined
for everything locally imported.
#822
Comments
Any updates on this, I have the same problem. If i imported files from my project they are |
If we get a minimal reproduction, we can identify the root cause. |
@cspotcode I have this minimal repro extracted from a project of mine. https://github.com/exequiel09/tsnode-bug |
Excellent, if it's an enum problem, I suspect it has to do with enum
elision. Const enums are removed from the emitted code unless
preserveConstEnums is turned on. With typechecking, the compiler can
inline the enum values. But in transpileOnly mode, it doesn't have type
info, so preserveConstEnums is required.
If you're trying to import an enum from a third-party library, that's where
you hit trouble. If they didn't compile with preserveConstEnums, then you
must use typechecking to get the type info.
…On Thu, Jul 9, 2020, 7:19 PM Exequiel Ceasar Navarrete < ***@***.***> wrote:
I have this minimal repro extracted from a project of mine.
https://github.com/exequiel09/tsnode-bug
You can run the command: npm run rekt:ts-node-bug.
Basically what it does is apps/sample-app/rekt-ts-node.ts import the enum
from libs/sample-lib/src/enums.ts but when imported the value in the
apps/sample-app/rekt-ts-node.ts becomes undefined
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#822 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35ODK3HBIJ67PDTUZAHDR2ZF6RANCNFSM4HHW7TTA>
.
|
It doesn't have to be enums. even a |
It might be circular dependencies. IIRC the code emitted for `export *
from ...` when converting to CommonJS doesn't handle circular dependencies.
It could also be path mappings. Our README mentions another tool you can
use to make node's resolver understand tsconfig "paths" mappings.
…On Thu, Jul 9, 2020, 9:13 PM Exequiel Ceasar Navarrete < ***@***.***> wrote:
It doesn't have to be enums. even a export const someVar = 1; will return
undefined if imported
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#822 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OGC77BAXFH2Q2GNDYDR2ZTMNANCNFSM4HHW7TTA>
.
|
Yes the example contains path mappings. But I also tried no path mappings and still shows |
Can you remove all non-essential elements of the reproduction? I see it includes some third-party dependencies. Are they necessary, or does the bug occur without them? The path mappings are not needed, so they should be removed as well. Anything that's not directly causing the bug is going to obscure it and prevent or delay us from implementing a bugfix. |
Yep the bug does occur without them. I just included them because I use it in a project that uses TypeORM. But will strip off those other deps and regenerate the lockfile for you. |
@cspotcode i pushed the changes without the typeorm related code plus there are now 2 examples there, one that imports a path-mapped code, and one that doesn't and both shows |
Thanks. I'm guessing it's an issue with the It seems Is there a reason you need to combine |
The import statements does not run without the |
@cspotcode Ok your comment regarding CommonJS triggered me. I tried 2 scenarios with package.json
|
@cspotcode I tried also the same scenario without the package.json field
|
@cspotcode I'll try first those 4 cases in my actual project. The 4 situations above were done using the reproduction repo. |
@cspotcode both number 2 in my comments worked perfectly. |
To summarize, |
Pretty sure there's no action required for this. |
But
tsc && node -r esm .
andnodemon -e ts -x 'tsc && node -r esm .'
works OK.Everything that I locally imported seems to be undefined with
ts-node
and I have triedmadge
anddetect-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 #819
The text was updated successfully, but these errors were encountered: