I was using graphql-code-generator successfully, but now when I run npm run codegen, I'm getting func is not a function error. As suggested in #3256, I removed node_modules, package-lock.json and npm install from scratch, but it didn't help.
I added a sandbox with same dependencies here: https://codesandbox.io/s/silly-haibt-3u7sq
Unfortunately, I cannot reproduce error there. Please advise.
✖ types/types.ts
TypeError: func is not a function
at .../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:19
Error message points to convertNameParts function:
function convertNameParts(str, func, removeUnderscore = false) {
if (removeUnderscore) {
return func(str);
}
return str
.split('_')
.map(s => func(s))
.join('_');
}
Please click to see full error message
TypeError: func is not a function
at .../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:19
at Array.map (<anonymous>)
at convertNameParts (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:10)
at opts (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:425:24)
at Object.convert (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:462:43)
at TsVisitor.convertName (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:488:78)
at TsVisitor._getTypeForNode (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:889:21)
at TsVisitor.NamedType (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:892:21)
at TsVisitor.NamedType (.../node_modules/@graphql-codegen/typescript/index.cjs.js:101:31)
at Object.visit (.../node_modules/graphql/language/visitor.js:242:26)
at Object.plugin (.../node_modules/@graphql-codegen/typescript/index.cjs.js:195:35)
at executePlugin (.../node_modules/@graphql-codegen/core/index.cjs.js:50:41)
at .../node_modules/@graphql-codegen/core/index.cjs.js:106:30
at Array.map (<anonymous>)
at Object.codegen (.../node_modules/@graphql-codegen/core/index.cjs.js:96:54)
at process (.../node_modules/@graphql-codegen/cli/bin.js:783:67)
TypeError: func is not a function
at .../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:19
at Array.map (<anonymous>)
at convertNameParts (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:10)
at opts (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:425:24)
at Object.convert (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:462:43)
at TsVisitor.convertName (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:488:78)
at TsVisitor._getTypeForNode (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:889:21)
at TsVisitor.NamedType (.../node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:892:21)
at TsVisitor.NamedType (.../node_modules/@graphql-codegen/typescript/index.cjs.js:101:31)
at Object.visit (.../node_modules/graphql/language/visitor.js:242:26)
at Object.plugin (.../node_modules/@graphql-codegen/typescript/index.cjs.js:195:35)
at executePlugin (.../node_modules/@graphql-codegen/core/index.cjs.js:50:41)
at .../node_modules/@graphql-codegen/core/index.cjs.js:106:30
at Array.map (<anonymous>)
at Object.codegen (.../node_modules/@graphql-codegen/core/index.cjs.js:96:54)
at process (.../node_modules/@graphql-codegen/cli/bin.js:783:67)
Thanks,
In order to help you, we need to reproduce it :) You can give us more details like OS, npm, node versions etc.
@ardatan thank you for the response. I completely agree, but I cannot reproduce it in codesandbox similar to #3256, but I get it again and again even installing from scratch.
node: 13.6.0
npm: 6.13.4
MacOS: 10.14.6
Other versions are as described in package.json
In case you need, I added tsconfig.json to sandbox.
EDIT: I thought, maybe it helps identifying the problem and I installed project using yarn from scratch. It worked as expected. However, I need a solution for npm.
I had this same issue with version 1.11.2
This comment fixed it for me, so maybe that's something to look into
TLDR: npm i -D change-case
Could you try with the exact canary version? (Without ^ mark)
1.11.3-alpha-21386b4a.87+21386b4a
Using below I'm getting same error with "npm install" from scratch. (yarn is still OK)
{
"@graphql-codegen/cli": "1.11.3-alpha-21386b4a.87",
"@graphql-codegen/typescript": "1.11.3-alpha-21386b4a.87",
"@graphql-codegen/typescript-graphql-files-modules": "1.11.3-alpha-21386b4a.87",
"@graphql-codegen/typescript-operations": "1.11.3-alpha-21386b4a.87"
}
Does this version work for you?
1.11.3-alpha-33d6634e.92
@ardatan still same error using 1.11.3-alpha-33d6634e.92
@ozum can you please create a reproduction in a repo/sandbox?
Update: I noticed that you already provided it, but we can't really assist without a reproduction we can run locally. I suggest to clean your env/cache and try again.
Hi @dotansimha and @ardatan, thank you for the responses.
I finally found a way to reproduce the error:
rm -rf node_modules/ package-lock.jsonnpm install --cache /tmp/empty-cache
Thanks,
I tried by following your steps and installing this canary version. I didn't get any errors with both
1.11.3-alpha-395be8af.104+395be8af and 1.11.3-alpha-33d6634e.92
https://codesandbox.io/embed/elastic-faraday-qz3bh?fontsize=14&hidenavigation=1&theme=dark
Notice that you shouldn't use any ^ or ~ in package.json because this might cause inconsistency.
@ardatan, I updated the sandbox and problem seems to be solved. Case may be closed. Thanks.
Fixed in v1.12.0