I have some problems using graphql-codegen. Here’s the best description I can give, hope it helps with the resolution.
My work environment:
- Windows 10
- Non-admin user
- NodeJS 16.0.0
- NPM 7.24.2
- Typescript 5.2.2
- Apollo server express 3.12.1
- GraphQL 15.8.0
The error is obtained when (according to the documentation) I init with this command: npx graphql-code-generator init
Note that for absolutely EVERY other NPM package I’ve used, I’ve never had ANY problems. Why then would graphql-codegen specifically be a problem? I don’t know..
node:internal/modules/cjs/loader:943
throw err;
^
Error: Cannot find module 'stream/web'
Require stack:
- C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclinode_modules@graphql-toolsapollo-engine-loadernode_modules@whatwg-nodefetchdistcreate-node-ponyfill.js
- C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclinode_modules@graphql-toolsapollo-engine-loadernode_modules@whatwg-nodefetchdistnode-ponyfill.js
- C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclinode_modules@graphql-toolsapollo-engine-loadercjsindex.js
- C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclicjsgraphql-config.js
- C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclicjsconfig.js
- C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclicjscli.js
- C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclicjsbin.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
at Function.Module._load (node:internal/modules/cjs/loader:773:27)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:93:18)
at createNodePonyfill (C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclinode_modules@graphql-toolsapollo-engine-loadernode_modules@whatwg-nodefetchdistcreate-node-ponyfill.js:31:24)
at Object.<anonymous> (C:UsersrandomDocumentsgitlabgame-backendnode_modules@graphql-codegenclinode_modules@graphql-toolsapollo-engine-loadernode_modules@whatwg-nodefetchdistnode-ponyfill.js:3:19)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Function.Module._load (node:internal/modules/cjs/loader:828:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\Users\random\Documents\gitlab\game-backend\node_modules\@graphql-codegen\cli\node_modules\@graphql-tools\apollo-engine-loader\node_modules\@whatwg-node\fetch\dist\create-node-ponyfill.js',
'C:\Users\random\Documents\gitlab\game-backend\node_modules\@graphql-codegen\cli\node_modules\@graphql-tools\apollo-engine-loader\node_modules\@whatwg-node\fetch\dist\node-ponyfill.js',
'C:\Users\random\Documents\gitlab\game-backend\node_modules\@graphql-codegen\cli\node_modules\@graphql-tools\apollo-engine-loader\cjs\index.js',
'C:\Users\random\Documents\gitlab\game-backend\node_modules\@graphql-codegen\cli\cjs\graphql-config.js',
'C:\Users\random\Documents\gitlab\game-backend\node_modules\@graphql-codegen\cli\cjs\config.js',
'C:\Users\random\Documents\gitlab\game-backend\node_modules\@graphql-codegen\cli\cjs\cli.js',
'C:\Users\random\Documents\gitlab\game-backend\node_modules\@graphql-codegen\cli\cjs\bin.js'
]
}
My package.json
{
"name": "game-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node build/src/index.js",
"build": "npx tsc",
"serve": "concurrently "npx tsc --watch" "nodemon -q build/src/index.js""
},
"repository": {
"type": "git",
"url": "SomethingIDon'tWantToShow"
},
"author": "SomethingIDon'tWantToShow",
"license": "ISC",
"dependencies": {
"@graphql-tools/graphql-file-loader": "^8.0.0",
"@graphql-tools/load": "^8.0.0",
"@graphql-tools/schema": "^8.5.1",
"@graphql-tools/utils": "^8.9.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.14",
"@types/graphql": "^14.5.0",
"@types/node": "^20.5.9",
"@types/sequelize": "^4.28.15",
"apollo-server-core": "^3.12.1",
"apollo-server-express": "^3.12.1",
"body-parser": "^1.20.2",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-session": "^1.17.3",
"graphql": "^15.8.0",
"graphql-subscriptions": "^2.0.0",
"keycloak-connect": "^22.0.2",
"pg": "^8.11.3",
"pg-hstore": "^2.3.4",
"sequelize": "^6.32.1",
"subscriptions-transport-ws": "^0.11.0",
"type-graphql": "^1.1.1"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/client-preset": "^4.1.0",
"@types/express-session": "^1.17.7",
"@types/ws": "^8.5.5",
"concurrently": "^8.2.1",
"nodemon": "^3.0.1",
"typescript": "^5.2.2"
}
}
I tried:
- Run the
npx graphql-code-generator init
command with the terminal in Administrator mode, this changes nothing. - Delete the
node_modules
andpackage-lock.json
folder and reinstall it withnpm install
, it doesn’t change anything. - Check that the files mentioned in the errors are present: They exist, also sames paths.
- Changing my version of NPM in more recent doesn’t change anything.
- Change my version of NodeJS, I see no point in it because the other backend projects my colleague is working on have exactly the same configuration and 0 problems in his side.
Any idea?
New contributor