Error: Cannot find module 'graphql'
MichaHumbel opened this issue · comments
We get the following error when trying to start our application after installing the nestjs-keycloak-admin package:
Full Error
Error: Cannot find module 'graphql'
- root/node_modules/@nestjs/graphql/dist/decorators/directive.decorator.js
- root/node_modules/@nestjs/graphql/dist/decorators/index.js
- root/node_modules/@nestjs/graphql/dist/index.js
- root/node_modules/nestjs-keycloak-admin/dist/main/utils/extract-request.js
- root/node_modules/nestjs-keycloak-admin/dist/main/guards/auth.guard.js
- root/node_modules/nestjs-keycloak-admin/dist/main/index.js
- root/dist/common/auth/auth.module.js
- root/dist/app.module.js
- root/dist/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (root/node_modules/@nestjs/graphql/dist/decorators/directive.decorator.js:4:19)
at Module._compile (node:internal/modules/cjs/loader:1099:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
We can't use nestjs-keycloak-admin without installing graphql, even though we don't use graphql. It runs after installing graphql manually as a dependency in our project.
Is there any way to use this package without installing graphql manually?
Hey @MichaHumbel, which version are you currently using?
Hey @MichaHumbel, which version are you currently using?
nestjs-keycloak-admin: 1.8.6
Node: v17.8.0
I don't think it's possible in a not-ugly way. I totally understand where this is coming from. What I can come up with is:
- You don't want to increase the node_modules size
- You don't want to install any package you don't use
Whole logic for detecting whether or not a request is coming from GraphQL is implemented in utils/extract-request.ts (https://github.com/anonrig/nestjs-keycloak-admin/blob/master/src/utils/extract-request.ts#L5)
Since extractRequest
function sits on top of the core logic of Nest.js applications (in all guards), I could not find a solution that does not duplicate existing code.
I believe there are some of the possible solutions (which might not be the best ones):
- Split each guard to GraphQL and HTTP: Importing each guard from respective places like
nestjs-keycloak-admin/graphql/guards
andnestjs-keycloak-admin/http/guards
- Dynamically load
@nestjs/graphql
package if the package is installed. If not, do not even try to understand if the request is a graphql request.
I'd be happy to discuss all possible solutions and reduce the size of this package.
same question here.... I'm not using graphQL so I shouldn't be forced to manually add @nestjs/graphql;
Tried this out with versions: 1.8.2 and 1.8.6 (get same issue for both versions)
For the latest version(1.8.7) I have other problem related with a require that sits somewhere in the code:
/Users/bernardo/Documents/incubeta-repos/creamos-client-management-service/node_modules/nestjs-keycloak-admin/dist/main/service.js:18
const keycloak_admin_client_1 = __importDefault(require("@keycloak/keycloak-admin-client"));
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/bernardo/Documents/incubeta-repos/creamos-client-management-service/node_modules/@keycloak/keycloak-admin-client/lib/index.js from /Users/bernardo/Documents/incubeta-repos/creamos-client-management-service/node_modules/nestjs-keycloak-admin/dist/main/service.js not supported.
Instead change the require of index.js in /Users/bernardo/Documents/incubeta-repos/creamos-client-management-service/node_modules/nestjs-keycloak-admin/dist/main/service.js to a dynamic import() which is available in all CommonJS modules.
@P1K3N due to @keycloak/keycloak-admin-client
being a ESM only package after 19.x release, it's required you to use ESM mode with Node.
Please look into the issues keycloak/keycloak-nodejs-admin-client#523, keycloak/keycloak-nodejs-admin-client#519 and keycloak/keycloak-nodejs-admin-client#487
@anonrig But these links are all 404
@anonrig But these links are all 404
It seems the keycloak-nodejs-admin-client repository is moved: https://github.com/keycloak/keycloak-nodejs-admin-client