Urql: No valid exports main found for @urql/core - ts-node in a Next.js project

Created on 22 Apr 2020  路  9Comments  路  Source: FormidableLabs/urql

Hello,

As promised, here is a minimal reproduction of an issue I am running into when trying to use the latest version of urql in a Next.js project ran by ts-node.

Note: All works as expected if I use next-urql: 0.3.3 and urql: 1.9.1.

Let me know if I can help with figuring this out.

urql version & exchanges:
urql: 1.9.7
next-urql: 0.3.7

Default exchanges used

Steps to reproduce

  1. Clone this repository: https://github.com/OriginalEXE/urql-import-problem-reproduction
  2. Run npm install
  3. Run npm run start and wait for the server to start
  4. Visit http://localhost:3000

Expected behavior
The website should show "Hello world"

Actual behavior
An error is thrown:

Error: No valid exports main found for '/Users/ante/Projects/urql-import-problem-reproduction/node_modules/@urql/core'
    at resolveExportsTarget (internal/modules/cjs/loader.js:611:9)
    at applyExports (internal/modules/cjs/loader.js:492:14)
    at resolveExports (internal/modules/cjs/loader.js:541:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:643:22)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:941:27)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (/Users/ante/Projects/urql-import-problem-reproduction/node_modules/urql/dist/urql.js:1:12)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Object.require.extensions.<computed> [as .js] (/Users/ante/Projects/urql-import-problem-reproduction/node_modules/ts-node/src/index.ts:832:44)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18) {
  code: 'MODULE_NOT_FOUND'
}

Most helpful comment

Woohoo, once I switched to Node 14.0.0, it all works. Thanks so much for making me try this 馃帀

I was on 13.2.0 and I can still reproduce this once I switch back to that version, so maybe something specific to that version triggers this issue.

In any case, thanks again for all of your work here, and hopefully, if anyone else out there runs into this issue, this thread helps them as well 馃槃

All 9 comments

Hiya :wave:

I followed your reproduction steps, but this seems to work for me in Node 12, 13, and 14. Is there maybe another factor that contributes to this problem?

Oh wow, really? That's great, it means there must be something wrong with my local setup. Let me try with a different version of node, and I'll get back to you. I appreciate you taking the time to try and reproduce this!

Woohoo, once I switched to Node 14.0.0, it all works. Thanks so much for making me try this 馃帀

I was on 13.2.0 and I can still reproduce this once I switch back to that version, so maybe something specific to that version triggers this issue.

In any case, thanks again for all of your work here, and hopefully, if anyone else out there runs into this issue, this thread helps them as well 馃槃

@kitten, can it be reopened and fixed for those who can鈥檛 switch to v14 yet? The issue seems to appear due to no file extension in main field of package.json.

@kinday Which versions do you have at your disposal?

I have tested my repo and it also works with these versions: 12.16.2, 13.3.0, and I assume there are more of them.

For the record, I have tried adding the extension to main and it did not help.

We switched back to 12.16.2 and it works. Didn鈥檛 work on 13.6.0 though.

So as far as I understand this is only an issue with ts-node? Seems like a bug on their end, but to explain the situation, the package.json:main field is there to work around a Webpack Resolution bug at the moment.

This issue will be resolved in Webpack but we will still have to keep it for older versions, so we can鈥檛 add the extension just for ts-node and break Webpack again.

Have you tried enabling the experimental modules mode? I鈥檓 not sure whether ts-node supports it and passes it through to node, but that will probably fix the issue for you

Oh, I missed it was about ts-node. In my case it was not working with regular node. We fixed it by using 12.x, so you can treat my comments as FYI.

Thanks for your time anyway.

I have not tested this with regular node, but can do so if needed to confirm. Since there are multiple versions of node that seem to be working, I think most people will be able to find a version within their supported ranges that does not have this problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wodnjs6512 picture wodnjs6512  路  3Comments

kitten picture kitten  路  3Comments

davidhouweling picture davidhouweling  路  4Comments

nicollecastrog picture nicollecastrog  路  3Comments

BjoernRave picture BjoernRave  路  3Comments