Skip to content

Bug: failed to resolve import "vite-plugin-node-polyfills/shims/process" #140

@Jinjiang

Description

@Jinjiang

Summary

It failed to resolve import "vite-plugin-node-polyfills/shims/process" in a package which is out of the workspace. This works in vite-plugin-node-polyfills 0.15.0. But after I upgrade to 0.24.0 it fails.

It happened in a very large repo. However, I tried to minimize the reproduction into this one:

https://github.com/Jinjiang/reproductions/tree/vite-polyfill-20251125

I believe they are the same root cause.

cd workspace-1
pnpm install
cd ../workspace-2
pnpm install
pnpm build

Then you will get:

❯ pnpm build

> workspace-2@ build /<reproduction-root>/workspace-2
> node run.mjs

vite v7.2.4 building client environment for production...
✓ 3 modules transformed.
✗ Build failed in 130ms
node:internal/modules/run_main:122
    triggerUncaughtException(
    ^

[vite]: Rollup failed to resolve import "vite-plugin-node-polyfills/shims/process" from "/<reproduction-root>/workspace-1/node_modules/.pnpm/[email protected]/node_modules/reflect-metadata/Reflect.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at viteLog (file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/config.js:34283:57)
    at file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/config.js:34317:73
    at file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-node-polyfills/dist/index.js:75:17
    at handleCircularDependancyWarning (/<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/node-stdlib-browser/helpers/rollup/plugin.js:29:3)
    at onwarn (file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-node-polyfills/dist/index.js:72:15)
    at file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/config.js:34317:28
    at onRollupLog (file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/config.js:34312:63)
    at onLog (file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/config.js:34115:4)
    at file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:20961:32
    at Object.logger [as onLog] (file:///<reproduction-root>/workspace-2/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:22848:9) {
  watchFiles: [
    '/<reproduction-root>/workspace-2/main.ts',
    '/<reproduction-root>/workspace-1/node_modules/.pnpm/[email protected]/node_modules/reflect-metadata/Reflect.js'
  ]
}

Node.js v22.14.0
 ELIFECYCLE  Command failed with exit code 1.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions