graphql-tools
graphql-tools copied to clipboard
@graphql-tools/mock 9.0.1 causes panic: Internal errors
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal.Please make sure the GraphQL Tools package versions under
package.json
matches yours. - [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
After upgrading from @graphql-tools/[email protected]
to @graphql-tools/[email protected]
my app builds are failing with:
error: panic: Internal error (while parsing "/srv/node_modules/@graphql-tools/mock/node_modules/@graphql-tools/utils/esm/debugTimer.js")
file: /srv/node_modules/@graphql-tools/mock/node_modules/@graphql-tools/utils/esm/debugTimer.js
=> Failed to build the preview
Error: Transform failed with 1 error:
error: panic: Internal error (while parsing "/srv/node_modules/@graphql-tools/mock/node_modules/@graphql-tools/utils/esm/debugTimer.js")
at failureErrorWithLog (/srv/node_modules/vite/node_modules/esbuild/lib/main.js:1650:15)
at /srv/node_modules/vite/node_modules/esbuild/lib/main.js:848:29
at responseCallbacks.<computed> (/srv/node_modules/vite/node_modules/esbuild/lib/main.js:703:9)
at handleIncomingPacket (/srv/node_modules/vite/node_modules/esbuild/lib/main.js:763:9)
at Socket.readFromStdout (/srv/node_modules/vite/node_modules/esbuild/lib/main.js:679:7)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
Rolling back to 9.0.0 makes the issue go away.
To Reproduce Steps to reproduce the behavior:
Working on it...
Expected behavior
No crash.
Environment:
- OS: MacOS
-
@graphql-tools/mock
: 9.0.1 - NodeJS: 20.3.1
Additional context
My app is Storybook, built via Vite.
It looks like a bug in ESBuild on your compile time not a runtime issue https://github.com/ardatan/graphql-tools/blob/master/packages/utils/src/debugTimer.ts#L4 If you think it is a runtime issue, could you create a reproduction on CodeSandbox? Thanks!
In my project, the error is reproduced.
Editing node_modules/.pnpm/@[email protected][email protected]/node_modules/@graphql-tools/utils/esm/debugTimer.js
fixed the error:
const debugNamesOngoing = new Set();
export function debugTimerStart(name) {
- const debugEnvVar = globalThis?.process.env['DEBUG'] || globalThis.DEBUG;
+ // ad hoc
+ const debugEnvVar = globalThis.process.env['DEBUG'] || globalThis.DEBUG;
if (debugEnvVar === '1' || debugEnvVar?.includes(name)) {
debugNamesOngoing.add(name);
console.time(name);
}
}
export function debugTimerEnd(name) {
if (debugNamesOngoing.has(name)) {
console.timeEnd(name);
}
}
UPDATE:
Install vite-plugin-replace
, then
vite.config.ts
import { replaceCodePlugin } from 'vite-plugin-replace';
// ...
export default defineConfig(({ mode, command }) => ({
plugins: [
replaceCodePlugin({
replacements: [
{
from: 'globalThis?.process.env',
to: 'globalThis.process.env',
},
],
}),
...
})
This solved the problem...