Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@graphql-tools/mock 9.0.1 causes panic: Internal errors #5843

Open
4 tasks
EvHaus opened this issue Jan 23, 2024 · 2 comments
Open
4 tasks

@graphql-tools/mock 9.0.1 causes panic: Internal errors #5843

EvHaus opened this issue Jan 23, 2024 · 2 comments

Comments

@EvHaus
Copy link

EvHaus commented Jan 23, 2024

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/mock@9.0.0 to @graphql-tools/mock@9.0.1 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.

@ardatan
Copy link
Owner

ardatan commented Jan 23, 2024

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!

@wand2016
Copy link

wand2016 commented Feb 5, 2024

In my project, the error is reproduced.

Editing node_modules/.pnpm/@graphql-tools+utils@10.0.13_graphql@16.8.1/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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants