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

Module not found: Can't resolve 'apollo-server-errors' #156

Open
snikch opened this issue Mar 9, 2023 · 8 comments
Open

Module not found: Can't resolve 'apollo-server-errors' #156

snikch opened this issue Mar 9, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@snikch
Copy link

snikch commented Mar 9, 2023

When importing this package into a next.js app, I get the following error. I believe because https://github.com/confuser/graphql-constraint-directive/blob/master/index.js#L135 attempts to require('apollo-server-errors') which is not a dependency of this package.

../../.yarn/__virtual__/graphql-constraint-directive-virtual-74b5cc573a/0/cache/graphql-constraint-directive-npm-4.1.2-695ac942e4-d61673215b.zip/node_modules/graphql-constraint-directive/index.js:135:39
Module not found: Can't resolve 'apollo-server-errors'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
../../packages/graphql/schemas/scalars/index.ts
../../packages/graphql/index.ts
./pages/api/graphql.ts

I'm not really sure what an appropriate resolution here is, short of moving the individual library support to alternative packages.

@velias
Copy link
Contributor

velias commented Mar 9, 2023

Hmm, this may be caused by presence of import {PluginDefinition} from "apollo-server-core"; in index.d.ts.
We can probably remove this import and make types for Apollo3 plugin weaker a bit.
Better solution might be to move Apollo3 plugin to separate js and d.ts file as apollo4 plugin, but it is a breaking change, so I'd like @confuser to help decide what to do.

@snikch
Copy link
Author

snikch commented Mar 9, 2023

@apollo/server is included in the package.json so I don't think this is the issue. I created a fork and simply removed the createApolloQueryValidationPlugin function and it is working successfully, so I believe it's definitely the issue that require('apollo-server-errors') is not listed as a dependency.

@velias
Copy link
Contributor

velias commented Mar 10, 2023

I do know nothing about next.js framework, so it is hard to determine. Is it and your project TypeScript or pure JavaScript?
In this module's package.json, apollo-server-core is in devDependency, and apollo-server-errors is its transitive dependency. It is intentionally not in dependencies not to be included in projects not using Apollo3. But devDependencies from modules are typically not included.
In the index.js, this require('apollo-server-errors') is intentionally in the code and not at the beginning, so should be used only if this code is used, but I'm not sure, maybe not. In index.d.ts it is imported at the beginning, so always.
So I'd expect your project uses TS, and that import in types file is the problem.

Anyway, as I wrote before, for me the best solution should be to extract Apollo 3 plugin (and maybe even Envelop plugin) to separate files. But this is a breaking change, so I'd like to know @confuser opinion first, before I start to implement it.

@snikch
Copy link
Author

snikch commented Mar 12, 2023

Agree that the solution would be to have separate plugins!

@davidruisinger
Copy link

Workaround:

Create a missing_apollo_types.d.ts (name does not matter) file in your project with the following content:

declare module 'apollo-server-core' {
  interface PluginDefinition {
    _: unknown
  }
}

@confuser
Copy link
Owner

confuser commented May 7, 2023

@velias I think the best solve which is a larger change is to create a monorepo with a core folder containing the main business logic and then each plugin being its own package. Otherwise it'll mean installing a bunch of dependencies that aren't needed just to cover multiple use cases

@confuser confuser added the bug Something isn't working label May 7, 2023
@velias
Copy link
Contributor

velias commented May 10, 2023

Agree, this is indeed the right solution. But it is a bit larger change ;-)

@lkrzyzanek
Copy link
Contributor

lkrzyzanek commented Jun 28, 2023

Given that Apollo 3 is not supported anymore it could be possible to simply remove Apollo 3 plugin at all with all its dependencies.

Docs (https://www.apollographql.com/docs/apollo-server/previous-versions) says:

Apollo Server 3 is deprecated and will transition to end-of-life on October 22nd, 2023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants