Skip to content
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

ERR_UNSUPPORTED_DIR_IMPORT when importing @apollo/client/core #11569

Closed
andreialecu opened this issue Feb 4, 2024 · 5 comments
Closed

ERR_UNSUPPORTED_DIR_IMPORT when importing @apollo/client/core #11569

andreialecu opened this issue Feb 4, 2024 · 5 comments

Comments

@andreialecu
Copy link
Contributor

Issue Description

I was migrating a test suite from jest to vitest, which seems to be stricter about how imports are handled, and ran into an issue where apollo-angular imports from @apollo/client/core, but this results in this error:

Error: Directory import '/home/projects/vitest-dev-vitest-7x42dr/node_modules/@apollo/client/core' is not supported resolving ES modules imported from /home/projects/vitest-dev-vitest-7x42dr/node_modules/apollo-angular/fesm2022/ngApollo.mjs
Did you mean to import @apollo/client/core/core.cjs?

The documentation mentions that imports from @apollo/client/core are recommended in: https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/#using-apollo-client-without-react

I initially created a bug report in Vite here: vitejs/vite#15795

A contributor there pointed out that this also fails with pure Node, which is true.

This was previously mentioned in the issue #9925 but was closed without being looked at.

I suspect this may become much more visible shortly because Angular is migrating to Vite for its build system, so it may uncover this issue for users of apollo-angular at least.

Related issues:
#9925
vitejs/vite#15795
kamilkisiela/apollo-angular#2172

Link to Reproduction

https://stackblitz.com/~/edit/vitest-dev-vitest-smbxnz?file=repro.mjs

Reproduction Steps

No response

@apollo/client version

3.9.2

@andreialecu
Copy link
Contributor Author

The correct solution could be to implement export maps. Here's some inspiration from @angular/core:

https://yarnpkg.com/package?q=%40angular%2Fcore&name=%40angular%2Fcore&file=%2Fpackage.json

andreialecu added a commit to andreialecu/apollo-client that referenced this issue Feb 4, 2024
andreialecu added a commit to andreialecu/apollo-client that referenced this issue Feb 4, 2024
@andreialecu
Copy link
Contributor Author

I opened PR #11570 with a change to build the export maps.

@alessbell
Copy link
Contributor

Hi @andreialecu 👋 The discussion related to this issue occurred over on your PR #11570 but I wanted to close the loop here: given kamilkisiela/apollo-angular#2172, and since we already have a tracking issue for adding exports in package.json #9976, I'm going to go ahead and close this issue. Thanks!

@alessbell alessbell closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2024
Copy link
Contributor

github-actions bot commented Feb 6, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

github-actions bot commented Mar 9, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants