Graphql-code-generator: Cannot find module graphql

Created on 28 Dec 2018  路  8Comments  路  Source: dotansimha/graphql-code-generator

After installing with npm install -g graphql-code-generator, I get the following error:

MacBook-Pro-2:stephanie-website ed$ gql-gen init
internal/modules/cjs/loader.js:582
    throw err;
    ^

Error: Cannot find module 'graphql'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/opt/local/lib/node_modules/graphql-code-generator/dist/load.js:39:17)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

I'm using npm 6.5.0 Mac OS Mojave, npm is installed from Macports.

Most helpful comment

@reconbot graphql is defined as devDependency and as peerDependency. We don't want to force a specific version of graphql because it might result in multiple copies of graphql (and that's not a good thing, because it will produce Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory. errors).

All 8 comments

Did you try to run npm i graphql?

Oops, that fixed it. Sorry. I'm still new to npm. I thought graphql would have been installed as a dependency...

Yes graphql should indeed have been installed as a dependency ... but it's defined faultly as a devDependencie ...

@reconbot graphql is defined as devDependency and as peerDependency. We don't want to force a specific version of graphql because it might result in multiple copies of graphql (and that's not a good thing, because it will produce Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory. errors).

Not listed as a peerDependency in package.json ...
Tool just cannot be used as a CLI without installing several dependencies manually at the moment.

Hi, that sounds fine. Did you mean to ping me?

@dotansimha I am still getting this error even after installing graphql! angular-cli app.
UPDATE
It seems to work by using yarn gql-gen init.

"dependencies": { "@angular/animations": "~7.2.0", "@angular/common": "~7.2.0", "@angular/compiler": "~7.2.0", "@angular/core": "~7.2.0", "@angular/forms": "~7.2.0", "@angular/platform-browser": "~7.2.0", "@angular/platform-browser-dynamic": "~7.2.0", "@angular/router": "~7.2.0", "core-js": "^2.5.4", "graphql": "^14.1.1", "rxjs": "~6.3.3", "tslib": "^1.9.0", "zone.js": "~0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.12.0", "@angular/cli": "~7.2.2", "@angular/compiler-cli": "~7.2.0", "@angular/language-service": "~7.2.0", "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codelyzer": "~4.5.0", "graphql-code-generator": "^0.16.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~3.1.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.1", "karma-jasmine": "~1.1.2", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.4.0", "ts-node": "~7.0.0", "tslint": "~5.11.0", "typescript": "~3.2.2" } }

Error:
````
$ gql-gen init
internal/modules/cjs/loader.js:582
throw err;
^

Error: Cannot find module 'graphql'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (C:Users...\AppData\Roaming\npm\node_modulesgraphql-code-generator\node_modulesgraphql-codegen-core\dist\schema\schema-to-template-context.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
````

@bhaidar does it still happens? If so, can you please open a new issue with more details?

Was this page helpful?
0 / 5 - 0 ratings