standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

3.2.21 and 3.2.22 bug #782

Closed steida closed 5 years ago

steida commented 5 years ago

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.

/Users/steida/dev/este/node_modules/graphql/language/parser.js:1
TypeError: Must provide Source. Received: undefined
    at parse (/Users/steida/dev/este/node_modules/graphql/language/parser.js:46:11)
    at Object.buildSchema (/Users/steida/dev/este/node_modules/graphql/utilities/buildASTSchema.js:502:43)
    at Client (/Users/steida/dev/este/node_modules/prisma-client-lib/dist/Client.js:162:34)
    at new Client (/Users/steida/dev/este/node_modules/prisma-client-lib/dist/makePrismaClientClass.js:33:27)
    at Object.<anonymous> (/Users/steida/dev/este/prisma/generated/prisma-client/index.ts:28:23)
    at Generator.next (<anonymous>)
[ERROR] 15:26:42 TypeError: Must provide Source. Received: undefined

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

NicoCevallos commented 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!

LiraNuna commented 5 years ago

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.

jdalton commented 5 years ago

Any chance any of you could provide a simplified repro?

steida commented 5 years ago

@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.

jdalton commented 5 years ago

Thanks! I'm thinking this may be addressed in our master branch already but not positive.

NicoCevallos commented 5 years ago

@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!

jdalton commented 5 years ago

@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"
steida commented 5 years ago

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",
jdalton commented 5 years ago

I think they're different scenarios. If you have a small repro for the ts-node bin directly I'll dig into that too.

steida commented 5 years ago

@jdalton Here is it sir https://github.com/steida/esmbug

20 works, 22 don't

mathieutu commented 5 years ago

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"
  } 
hansemannn commented 5 years ago

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.

NicoCevallos commented 5 years ago

@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?

steida commented 5 years ago

@NicoCevallos Sure, because in repo there is the last working esm version. "esm": "3.2.20" Try 3.2.22

NicoCevallos commented 5 years ago

@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.

steida commented 5 years ago

So ts-node-dev was recently fixed and it works. https://github.com/whitecolor/ts-node-dev/issues/65

steida commented 5 years ago

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",

steida commented 5 years ago

Awesome. Thank you, everyone.

jdalton commented 5 years ago

@steida Thanks for the good news update!