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

"injectConfigValues is not a function" error when running multiple vite-node processes in parallel #7479

Open
6 tasks done
ethanjdiamond opened this issue Feb 12, 2025 · 3 comments · May be fixed by #7480
Open
6 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node

Comments

@ethanjdiamond
Copy link

Describe the bug

Hi!

We have a monorepo where we run a bunch of internal tools in parallel as a lint step, a good portion of which are run via vite-node. Since upgrading to from vite-node 2.1.3. to 3.0.5 we pretty frequently get this error when running our lint step:

lint:lint.project-configs | file:///Users/ethandiamond/Projects/monorepo/node_modules/.pnpm/vite@6.0.11_@types+node@22.12.0_terser@5.37.0/node_modules/vite/dist/node/chunks/dep-M1IYMR16.js:46342
    lint:lint.project-configs |         return defineReplacer(injectConfigValues(code));
    lint:lint.project-configs |                               ^
    lint:lint.project-configs | 
    lint:lint.project-configs | TypeError: injectConfigValues is not a function
    lint:lint.project-configs |     at TransformPluginContext.transform (file:///Users/ethandiamond/Projects/monorepo/node_modules/.pnpm/vite@6.0.11_@types+node@22.12.0_terser@5.37.0/node_modules/vite/dist/node/chunks/dep-M1IYMR16.js:46342:31)
    lint:lint.project-configs |     at EnvironmentPluginContainer.transform (file:///Users/ethandiamond/Projects/monorepo/node_modules/.pnpm/vite@6.0.11_@types+node@22.12.0_terser@5.37.0/node_modules/vite/dist/node/chunks/dep-M1IYMR16.js:47401:19)
    lint:lint.project-configs |     at loadAndTransform (file:///Users/ethandiamond/Projects/monorepo/node_modules/.pnpm/vite@6.0.11_@types+node@22.12.0_terser@5.37.0/node_modules/vite/dist/node/chunks/dep-M1IYMR16.js:41198:27) {
    lint:lint.project-configs |   plugin: 'vite:client-inject',
    lint:lint.project-configs |   id: '/Users/ethandiamond/Projects/monorepo/node_modules/.pnpm/vite@6.0.11_@types+node@22.12.0_terser@5.37.0/node_modules/vite/dist/client/env.mjs',
    lint:lint.project-configs |   pluginCode: 'const context = (() => {\n' +
    lint:lint.project-configs |     '  if (typeof globalThis !== "undefined") {\n' +
    lint:lint.project-configs |     '    return globalThis;\n' +
    lint:lint.project-configs |     '  } else if (typeof self !== "undefined") {\n' +
    lint:lint.project-configs |     '    return self;\n' +
    lint:lint.project-configs |     '  } else if (typeof window !== "undefined") {\n' +
    lint:lint.project-configs |     '    return window;\n' +
    lint:lint.project-configs |     '  } else {\n' +
    lint:lint.project-configs |     '    return Function("return this")();\n' +
    lint:lint.project-configs |     '  }\n' +
    lint:lint.project-configs |     '})();\n' +
    lint:lint.project-configs |     'const defines = __DEFINES__;\n' +
    lint:lint.project-configs |     'Object.keys(defines).forEach((key) => {\n' +
    lint:lint.project-configs |     '  const segments = key.split(".");\n' +
    lint:lint.project-configs |     '  let target = context;\n' +
    lint:lint.project-configs |     '  for (let i = 0; i < segments.length; i++) {\n' +
    lint:lint.project-configs |     '    const segment = segments[i];\n' +
    lint:lint.project-configs |     '    if (i === segments.length - 1) {\n' +
    lint:lint.project-configs |     '      target[segment] = defines[key];\n' +
    lint:lint.project-configs |     '    } else {\n' +
    lint:lint.project-configs |     '      target = target[segment] || (target[segment] = {});\n' +
    lint:lint.project-configs |     '    }\n' +
    lint:lint.project-configs |     '  }\n' +
    lint:lint.project-configs |     '});\n'
    lint:lint.project-configs | }
    lint:lint.project-configs | 
    lint:lint.project-configs | Node.js v20.11.1

Reproduction

As best I can tell this only seems to come up when running several vite-node processes in parallel. I made a bare-bones repro in a repo here. Clone that repro and then run npm run repro. This will run a whole bunch of vite-node commands in parallel, a bunch of which will trigger the error.

System Info

System:
    OS: macOS 15.3
    CPU: (10) arm64 Apple M1 Pro
    Memory: 139.92 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.local/share/mise/installs/node/20.11.1/bin/node
    npm: 10.2.4 - ~/.local/share/mise/installs/node/20.11.1/bin/npm
    pnpm: 9.15.4 - ~/.local/share/mise/installs/pnpm/9.15.4/bin/pnpm
    Watchman: 2024.10.07.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 133.0.6943.54
    Safari: 18.3
  npmPackages:
    playwright: workspace:* => 1.49.0 
    vite: workspace:* => 6.1.0 
    vitest: workspace:* => 3.0.5

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 13, 2025

Hmm, it sounds very odd if there's any influence between processes. How about pinning "vite": "^5"?
(Oh, maybe it's just flaky in general and it just shows up when running many times. running parallel is not an actual case?)

@hi-ogawa hi-ogawa added vite-node p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Feb 13, 2025
@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 13, 2025

It looks like this is due to Vite 6 side change of how buildStart works. Vite-node manually calling this was necessary on Vite 5, but it's not needed on Vite 6 and actually causing some issues with plugin hook order.

await server.pluginContainer.buildStart({})

Here is a reproduction https://stackblitz.com/edit/vitejs-vite-szzqh63c?file=repro.js.

[repro:buildStart:in]
[repro:transform] /home/projects/vitejs-vite-szzqh63c/package.json
[repro:buildStart:out]

@hi-ogawa hi-ogawa linked a pull request Feb 13, 2025 that will close this issue
6 tasks
@ethanjdiamond
Copy link
Author

Thanks for the quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants