Open chadxz opened 5 months ago
Hey @chadxz 👋
Thanks for opening this! I'll do my best to take a look at this today. I'm currently working on a reproduction for a potential React bug and I'm on vacation starting tomorrow for the next week. If not me, I'll see if one of the other maintainers has some bandwidth to take a look. Thanks!
Thanks for your patience!
There are two things that look like would get this to work for you. Either you'll need to specify your app with type: "module"
in package.json
so that you aren't using CommonJS, or you'll need to update your import to ensure you'll getting the CommonJS build. You can do this using the main.cjs
path.
import {
ApolloClient,
InMemoryCache,
type NormalizedCacheObject,
} from "@apollo/client/main.cjs";
While this is less than ideal, this should get you what you need for now. We'll be adding proper ESM support in v4 to avoid this issue going forward. Hope this helps!
Thanks for the suggestion @jerelmiller!
I tried this and it looks like that is incompatible with TypeScript as well, unless I'm still missing something:
This is using @apollo/client@3.10.8
The same is true on the reproduction link:
@chadxz thats...odd. I used your original reproduction and forked it to check. Here is my fork: https://codesandbox.io/p/devbox/gifted-thompson-y875p2?file=%2Findex.ts%3A4%2C8
If you run npx tsc
or yarn tsc
(pick your favorite) in the terminal, it passes just fine.
Without /main.cjs
:
With /main.cjs
Odd that you're still seeing that error in the reproduction 🤔
If you hover over the 3 dots at the beginning of the package name in your screenshot you'll probably see the same message I am seeing.
I can confirm that compiling works fine in the reproduction, but I think that's because it has a minimal tsconfig.json. If you add "strict": true
to the tsconfig.json it will spit out the error at compile time.
Also facing this issue, is there any progress?
Adding the .d.ts
file for @apollo/core/main.cjs
gets rid of TS's complaints, but doesn't feel quite right that it's necessary to do this...
To confirm, this is with module: 'Node16'
, moduleResolution: 'Node16'
, strict: true
in the tsconfig, where I'm building a library that exposes some logging functionality for consumers, which makes use of the ApolloLink
from @apollo/client
+1.
I also have this issue with Node16.
Same issue with NodeNext
+1
you can add your own package.json "type": "module"
Issue Description
Trying to upgrade from
3.4.17
to latest and have started running into this error as of3.5.0
:I have included a reproduction link. Simply using
"module": "NodeNext"
in tsconfig.json will cause this. This is the recommended setting for "modern Node.js projects" per the TypeScript documentation. Do you have any recommendations on how to address this? My project is not ESM today.Link to Reproduction
https://codesandbox.io/p/devbox/recursing-yalow-s8fmpr
Reproduction Steps
Run
tsc
in the terminal of the repro. Main config setting to set is"module": "NodeNext"
in tsconfig.json@apollo/client
version3.10.4