graphql-code-generator: TypeError: func is not a function
When running graphql-codegen to generate typings, our team suddenly started to get this error today, after months of working without issues. I updated to latest version of all plugins, but the issue persists:
TypeError: func is not a function
at <path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:19
at Array.map (<anonymous>)
at convertNameParts (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:10)
at opts (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:425:24)
at Object.convert (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:462:43)
at TsVisitor.convertName (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:488:78)
at TsVisitor._getTypeForNode (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:889:21)
at TsVisitor.NamedType (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:892:21)
at TsVisitor.NamedType (<path-to-project-folder>/node_modules/@graphql-codegen/typescript/index.cjs.js:101:31)
at Object.visit (<path-to-project-folder>/node_modules/graphql/language/visitor.js:242:26)
at Object.plugin (<path-to-project-folder>/node_modules/@graphql-codegen/typescript/index.cjs.js:195:35)
at executePlugin (<path-to-project-folder>/node_modules/@graphql-codegen/core/index.cjs.js:50:41)
at <path-to-project-folder>/node_modules/@graphql-codegen/core/index.cjs.js:106:30
at Array.map (<anonymous>)
at Object.codegen (<path-to-project-folder>/node_modules/@graphql-codegen/core/index.cjs.js:96:54)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Update - seems like the issue is only above version 1.9.1.
Expected behavior Generated types
Environment:
- OS: MacOS 10.14.6
- “@graphql-codegen/cli”: “^1.11.2”,
- “@graphql-codegen/typescript”: “^1.11.2”,
- “@graphql-codegen/typescript-apollo-angular”: “^1.11.2”,
- “@graphql-codegen/typescript-operations”: “^1.11.2”,
- “@graphql-codegen/typescript-resolvers”: “^1.11.2”,
- NodeJS: 12.11.1
codegen.yml
schema: http://localhost:1337/graphql
generates:
./src/app/eddy/generated/graphql.ts:
schema: ./src/app/eddy/modules/graphql/client-schema.ts
documents: ./src/**/*.graphql
config:
ngModule: ../modules/graphql-lazy-service/graphql-lazy-service.module#GraphqlLazyServiceModule
plugins:
- typescript
- typescript-operations
- typescript-apollo-angular
./aveiro-server/src/graphql/generated/resolvers-types.ts:
plugins:
- typescript
- typescript-resolvers
config:
scalars:
ObjectId: GQLObjectId
Date: GQLDate
require:
- ts-node/register
Workaround Fix versions in your package.json: “@graphql-codegen/cli”: “1.9.1”, “@graphql-codegen/typescript”: “1.9.1”, “@graphql-codegen/typescript-apollo-angular”: “1.9.1”, “@graphql-codegen/typescript-operations”: “1.9.1”, “@graphql-codegen/typescript-resolvers”: “1.9.1”,
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 32 (2 by maintainers)
Commits related to this issue
- fix(naming-convention): revert and pin change-case-all dependency for workaround #3256 — committed to dotansimha/graphql-code-generator by ardatan 3 years ago
- fix(naming-convention): revert and pin change-case-all dependency for workaround #3256 (#5710) — committed to dotansimha/graphql-code-generator by ardatan 3 years ago
Could you all update all codegen packages to the latest version and try again?
Work perfectly with the current versions. Thank you @ardatan
We’re aware of the issue and working on it. Thanks for your patience.
seems exact package which causes issue is
change-case-allif you will explicitly lock it’s version on
1.0.12it will work fineIn our case, the
pascal-casedependency (v2.0.0) didn’t match the included type definition. The type def isimport { pascalCase } from 'pascal-case'where as the js seems to be exporting the func as default, e.g.import pascalCase from 'pascal-case'.I just tried installing the latest version of pascal-case (v3.1.1) explicitly and it fixed the issue.
this cause again in case using
not cause on
1.17.14.once updated to ‘1.17.15’ then even if I revert the version, the problem will continue to occur. some dependencies in this module must be the cause.
it looks graphql-codegen has a dependency of “change-case”: “^3.0.0”, but change-case has dependency of “pascal-case”: “^2.0.0”, so I think we need to update change-case to latest version.
npm i -D change-case(it worked for me!)or wait for maintainers to update the dependency to “change-case”: “^4.1.1”
Your configuration seems wrong. Under
generates, we should have the output filenamesInstead of using js file, I’d recommend to have YML file like below;
And you can run codegen with dotenv like this;
@ardatan I tried reproducing this error, it’s not easy but I finally found something! It seems like the error is not related to the setup (client or server) at all - but has something to do with versioning - maybe npm.
When I removed the
package-lock.json(something I otherwise always try to avoid as a solution) and did a fresh install withnpm i @graphql-codegen/{cli,typescript,typescript-apollo-angular,typescript-operations,typescript-resolvers}@latest, the error was gone 🤔Only thing is that now, I can’t reproduce 🤷🏾♂️
It worked ! Thanks a ton ! @ardatan
Codesandbox with the error: https://codesandbox.io/s/wispy-darkness-nxtp9
@ardatan It works perfectly too! thank you!
@ardatan thank you so much, you are the best!
@dotansimha We don’t use
change-caseanymore and I don’t think even npm gets confused with^😃