Closed steida closed 5 years ago
Hi, I figured out the same issue here. I export whatever (a function, string, number, etc) from a file and when I try to use it from another file I get undefined instead of the value I exported before. So sad.
I faced this issue with the version 3.2.22, so please @steida update the issue title please, and strong the recommendation to use 3.2.20 version. Thanks!
I have the same issue. I'm not yet able to narrow it down.
Just so we can compare notes, I'm using ts-node
with ts-loader
and tsconfig-paths
and I'm invoking it with ts-node -r esm -r tsconfig-paths/register
Hopefully this will help us narrow some things down.
Any chance any of you could provide a simplified repro?
@jdalton I would like but I encountered it in big github.com/este/este. I will try to recreate it from scratch. Btw thank you for your awesome work.
Thanks! I'm thinking this may be addressed in our master
branch already but not positive.
@jdalton I created a repo to reproduce the issue with the minimal dependencies. Looks like the problem is when you use esm
along with ts-node
.
https://github.com/NicoCevallos/esm-782
Just run npm run test
to check the issue.
Enjoy it!
@NicoCevallos
For your example you must run esm
before ts-node/register
. If I change the test
script to the following it works:
"test": "node -r esm -r ts-node/register src/main.ts"
Hmm, but what to do when we use ts-node and ts-node-dev directly?
"ts": "ts-node -T -r esm -r dotenv/config",
"ts:watch": "ts-node-dev --respawn --no-notify --transpileOnly -r esm -r dotenv/config",
I think they're different scenarios. If you have a small repro for the ts-node bin directly I'll dig into that too.
@jdalton Here is it sir https://github.com/steida/esmbug
20 works, 22 don't
I can confirm the issue with 3.2.21 and 3.2.22. It caused https://github.com/mathieutu/vue-cli-plugin-express/issues/15 and https://github.com/mathieutu/vue-cli-plugin-express/issues/14 on my side.
No problem with
"resolutions": {
"esm": "3.2.21"
}
This issue also breaks our express + mocha + supertest setup:
ReferenceError: domain is not defined\n at Proxy.propertyIsEnumerable (<anonymous>)"
I know this is not much, but if I should provide more logs, let me know!
Note: The root cause are changes in 3.2.21, since 3.2.22 only reverted one previous issue.
@mathieutu @hansemannn How are you loading esm
? are you loading it along with any other plugin for node?
Check I faced the same issue and In my case the problem was how I was loading it. First should be esm
, then ts-node/register
.
Also I faced the same issue with nyc
when I use TypeScript with "module": "esnext"
. For that I already loaded a bug for them https://github.com/istanbuljs/nyc/issues/1094
@steida I cloned your repo and after install dependencies I ran yarn dev
and it works perfect, the code is printing bar
in the console. Is that what you expected to happen?
@NicoCevallos Sure, because in repo there is the last working esm version. "esm": "3.2.20" Try 3.2.22
@steida Sorry, you're right. Anyways I changed esm
to version 3.2.22
and to fix the issue I needed to change the module
to commonjs
in the tsconfig.json
file.
So I guess it's something that ts-node-dev should solve. The same what I faced with nyc
. And that doesn't happen if you use node -r esm -r ts-node/register
.
So ts-node-dev was recently fixed and it works. https://github.com/whitecolor/ts-node-dev/issues/65
And ts-node was fixed by replacing
"ts": "ts-node -T -r esm -r dotenv/config",
with
"ts": "node -r esm -r ts-node/register/transpile-only -r dotenv/config",
Awesome. Thank you, everyone.
@steida Thanks for the good news update!
So I updated esm dependency in my big fat starter kit https://github.com/este/este and it took me a while to figure out that esm somehow changed behavior.
I have no idea what can be wrong.
The "test case" can be https://github.com/este/este/tree/a512bcd8d59de3c9288c354f2b443af469d32060
I know it will not help but maybe someone will google it and use resolutions "esm": "3.2.20" as temp workaround