Skip to content

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

@ethanjdiamond

Description

@ethanjdiamond

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions