Closed nikitalocalhost closed 3 weeks ago
I have the same issue. For now I'm using patch-package to apply the fix you suggested (replacing template
with template.smart
).
Same issue, seems to me like an issue with Babel+ESM. I tried updating @babel/helper-plugin-utils
and @babel/template
in client-preset
, but that didn't seem to fix it.
@taobojlen have you submitted a PR with your change?
@n1ru4l The fix is available, can we please get this fixed?
The pnpm patch fixes it.
patches/@graphql-codegen__client-preset@4.2.6.patch
diff --git a/esm/babel.js b/esm/babel.js
index 3d281239438d23d6df9597b1e01a6e97cb9a92ea..3ed3e23f5a299ad8d6b699006b2cbdb21a3aa36f 100644
--- a/esm/babel.js
+++ b/esm/babel.js
@@ -1,8 +1,9 @@
import * as path from 'path';
import { declare } from '@babel/helper-plugin-utils';
-import template from '@babel/template';
+import _template from '@babel/template';
import { ClientSideBaseVisitor } from '@graphql-codegen/visitor-plugin-common';
import { buildSchema, parse } from 'graphql';
+const template = _template.default;
const noopSchema = buildSchema(`type Query { _: Int }`);
export default declare((api, opts) => {
const visitor = new ClientSideBaseVisitor(noopSchema, [], {}, {});
package.json
...
"pnpm": {
"patchedDependencies": {
"@graphql-codegen/client-preset@4.2.6": "patches/@graphql-codegen__client-preset@4.2.6.patch"
}
}
@pksunkara @felix98765 @sebvilhelm @taobojlen Sorry for the long delay, but this is now finally addressed within https://github.com/dotansimha/graphql-code-generator/pull/9817
Gonna cut a release in a few minutes: https://github.com/dotansimha/graphql-code-generator/pull/10074
Which packages are impacted by your issue?
@graphql-codegen/client-preset
Describe the bug
When building app with vite using babelOptimizerPlugin from client-preset, building throws an error:
This happens when
package.json
type set to module.When manually changing
node_modules/@graphql-codegen/client-preset/esm/babel.js:42
template
totemplate.smart
build is successfulYour Example Website or App
https://stackblitz.com/edit/github-p5p2s9?file=vite.config.ts
Steps to Reproduce the Bug or Issue
From example:
yarn vite build
From vite react-ts template:
@graphql-codegen/cli
and@graphql-codegen/client-preset
to templateconst config: CodegenConfig = { schema: 'schema.graphql', documents: ['src/*/{js,jsx,ts,tsx}'], ignoreNoDocuments: true, generates: { './src/lib/gql/': { preset: 'client-preset', }, }, };
export default config;
const USER_QUERY = graphql(
query UserQuery($id: ID!) { user(id: $id) { id username email } }
);Expected behavior
Build successful
Screenshots or Videos
No response
Platform
graphql
version: 16.8.1@graphql-codegen/cli
version: 5.0.0@graphql-codegen/client-preset
version: 4.1.0Codegen Config File
Additional context
No response