fix: resolve shim imports from packages outside workspace#141
Open
Jinjiang wants to merge 2 commits intodavidmyersdev:mainfrom
Open
fix: resolve shim imports from packages outside workspace#141Jinjiang wants to merge 2 commits intodavidmyersdev:mainfrom
Jinjiang wants to merge 2 commits intodavidmyersdev:mainfrom
Conversation
Fixes an issue where Rollup failed to resolve shim imports (like 'vite-plugin-node-polyfills/shims/process') from packages located outside the main workspace during the build phase. The root cause was that @rollup/plugin-inject only provides a transform hook but not a resolveId hook. When external packages reference Node.js globals, the inject plugin transforms them into import statements, but Rollup couldn't resolve these imports from cross-workspace packages. Added a custom Rollup plugin 'vite-plugin-node-polyfills:shims-resolver' that provides a resolveId hook to properly resolve shim imports by mapping them to their absolute file paths using require.resolve(). This fix applies to all three global shims: buffer, global, and process.
|
@sapphi-red what do you think? could solve my issue as well? |
afn
added a commit
to superdoc-dev/superdoc
that referenced
this pull request
Dec 17, 2025
Apply patch from davidmyersdev/vite-plugin-node-polyfills#141 which addresses davidmyersdev/vite-plugin-node-polyfills#140. Note - this appears to be the same issue as davidmyersdev/vite-plugin-node-polyfills#81.
2 tasks
afn
added a commit
to superdoc-dev/superdoc
that referenced
this pull request
Dec 18, 2025
Apply patch from davidmyersdev/vite-plugin-node-polyfills#141 which addresses davidmyersdev/vite-plugin-node-polyfills#140. Note - this appears to be the same issue as davidmyersdev/vite-plugin-node-polyfills#81.
afn
added a commit
to superdoc-dev/superdoc
that referenced
this pull request
Dec 19, 2025
Apply patch from davidmyersdev/vite-plugin-node-polyfills#141 which addresses davidmyersdev/vite-plugin-node-polyfills#140. Note - this appears to be the same issue as davidmyersdev/vite-plugin-node-polyfills#81.
|
I can attest this to be working well for my project. Thanks @Jinjiang for the patch! |
afn
added a commit
to superdoc-dev/superdoc
that referenced
this pull request
Dec 29, 2025
Apply patch from davidmyersdev/vite-plugin-node-polyfills#141 which addresses davidmyersdev/vite-plugin-node-polyfills#140. Note - this appears to be the same issue as davidmyersdev/vite-plugin-node-polyfills#81.
afn
added a commit
to superdoc-dev/superdoc
that referenced
this pull request
Dec 29, 2025
Apply patch from davidmyersdev/vite-plugin-node-polyfills#141 which addresses davidmyersdev/vite-plugin-node-polyfills#140. Note - this appears to be the same issue as davidmyersdev/vite-plugin-node-polyfills#81.
harbournick
pushed a commit
to superdoc-dev/superdoc
that referenced
this pull request
Dec 30, 2025
* feat: bump node to v22.21.1 (latest v22) in .nvmrc
* feat: switch to pnpm workspace
Eliminate package-lock.json in favor of pnpm-lock.yaml
* feat: move package versions to pnpm catalog (via codemod)
Run `pnpx codemod pnpm/catalog` to generate initial catalog. Still to
do: update inconsistent versions of dependent packages.
* feat: move more dependencies to pnpm catalog
* feat: add "source" conditional export to super-editor package
Add "source" to conditions in the superdoc vite build definition so that
@harbour-enterprises/super-editor is imported from `src` rather than
from the built package in `dist`.
* feat: move more dependencies to pnpm catalog
* feat: eliminate aliases for drilling into external packages
Avoid drilling into other packages' source with aliases like:
'@superdoc/common': fileURLToPath(new URL('../../shared/common', import.meta.url)),
and instead use those packages directly. Leverage the "source" condition
so that we can continue importing source files rather than requiring the
dependent package to be built before use.
* feat: eliminate aliases from tsconfig and add "source" condition
For parity with vite config, remove unnecessary aliases for packages
that exist in the workspace, and add the "source" condition via
customConditions so that tsserver can recognize imports from package
source.
* fix: add missing dependency: measuring-dom depends on word-layout
* fix: use pnpm instead of npm in install-rollup-binary.mjs
* feat: approve canvas, esbuild, and vue-demi to run build scripts
* fix: update path printed in ensure-types output
* fix: run superdoc tsc without "source" custom condition
* fix: use pnpm instead of npm in package.json scripts
* fix: import nextTick from vue instead of process
* feat: use pnpm/pnpx in github actions
* feat: use pnpm for building e2e-tests template vue app
* fix: downgrade vitest to v3 due to breaking changes in v4
Also upgrade jsdom and canvas to their latest versions.
* fix: use pinned commit hash for github action
Address CodeQL warning
* feat: remove install-rollup-binary.mjs
This doesn't seem to be needed; according to the [rollup
docs](https://github.com/rollup/rollup/blob/master/docs/migration/index.md#general-changes),
the native code is automatically installed.
* fix: don't overwrite default test exclusions in vite.config.mjs
See https://main.vitest.dev/config/exclude.html#example
* fix: add missing deps (yjs, y-protocols, lib0) to collaboration-yjs
* fix: add missing prosemirror devDependencies to superdoc
* fix: source export from layout-bridge is src/index.js, not ts
* feat: rename @harbour-enterprises/super-editor to @superdoc/super-editor
* feat: eliminate super-editor path aliases
Only use the path aliases in the super-editor and superdoc packages.
Also add `converter/internal/*` export from super-editor, where imports
of specific files are required.
* fix: fix typescript errors when building layout-engine packages
1. Add dependency on @superdoc/word-layout for WordParagraphLayoutOutput
type
2. Fix several typescript errors in renderer.ts
3. For now, add `--noCheck` to the tsc build in the pdf painter package
to allow package to be built despite pending TS errors
* fix: build layout-engine/tests with "source" condition set
Note that this requires adding back the super-editor aliases to allow
references within the super-editor source to @core etc to be resolved.
* feat: add shared config for vitest with "source" condition
Include baseConfig in all vitest configuration to resolve using "source"
condition and to set super-editor aliases
* feat: start normalizing tsconfig.json across projects
Still some work to do to eliminate duplication, but:
* Eliminate `references`, since packages are now imported with their
proper package names rather than importing across package boundaries
* Move common settings into tsconfig.base.json
* fix: various build issues
* Fix layout-bridge export (index.ts, not index.js)
* Add missing dependencies
* Add "./*" export from pm-adapter to allow importing
@superdoc/pm-adapter/attributes/paragraph.js (note: consider exporting
this from the top-level index to avoid needing this deep export)
* feat: prevent imports across package boundaries
Add eslint-plugin-import-x to prevent importing across package
boundaries, e.g.
import { measureBlock } from '../../../measuring/dom/src/index'
* fix: approve postbuild script for unrs-resolver
* fix: address linter errors from eslint-plugin-import-x
* fix: remove "src/index" from imports, add dependencies
Also update the regexp in packages/superdoc/vite.config.js to add
additional known @superdoc/XXX packages
* chore: fix unit tests for pm-adapter (#1550)
* fix: add missing deps to pm-adapter, add fixtures to tsconfig includes
* chore: move more packages to pnpm catalog
* fix: work around bug in vite-plugin-node-polyfills
Apply patch from
davidmyersdev/vite-plugin-node-polyfills#141
which addresses
davidmyersdev/vite-plugin-node-polyfills#140.
Note - this appears to be the same issue as
davidmyersdev/vite-plugin-node-polyfills#81.
* feat: move examples into its own pnpm workspace
Add override for superdoc package to use the locally packed version
instead of pulling it from the npm repository, while still allowing
examples to be used as fully standalone packages independent of the pnpm
workspace.
* fix: ensure that all superdoc exports are included in dist
1. Remove `common` from package.json; this doesn't appear to be present
in the package prior to this branch.
2. Remove `super-editor/style.css`, since the exported `style.css`
contains a superset of the super-editor styles
3. Fix source path for copying images from pdfjs
* feat: generate superdoc type declarations using vite-plugin-dts
Avoid separately running tsc to generate types.
Note: there's an issue (present in the main branch as well) which is
that the declaration files in the superdoc package reference imports
from internal packages rather than re-exporting these types. This should
probably be resolved in a separate PR.
* fix: build superdoc prior to running visual tests
* fix: get visual tests to run
1. Change playwright command line to run `pnpm dev` in each package
2. Change format of test-config.js to list package paths, rather than
full command lines
3. Add missing dependencies
* feat: add semantic-release-pnpm for semantic-release
* feat: add Dockerfile for running visual tests
To run visual tests in Docker and update the snapshots:
cd examples/tests
pnpm run docker:build
pnpm run docker:update-screenshots
* fix: update snapshots from visual tests
* feat: upload visual test results on failure
* fix: update snapshots from visual tests, using actuals from gh action
* fix: increase latency targets for performance tests
The newer version of jsdom (27.3.0) is significantly slower than the
previous version (25.0.1). Relax the target latency metrics in the
performance test to accommodate the slower jsdom package.
* fix: eliminate references to "@/" import alias
Use @core, @utils, etc for imports from super-editor
* fix: add superdoc source aliases to packages/ai/vitest.config.mjs
* fix: increase latency target even further for perf tests
* fix: update visual test snapshots
* fix: issues with react examples
* Add missing styled-jsx dependency
* Remove <React.Strict> which was causing SuperDoc to be rendered twice.
This resulted in errors, even after adding
`editorRef.current.destroy()` to the useEffect unmount callback,
suggesting that SuperDoc#destroy() is not completely reverting the
state of the DOM.
* fix: update snapshots for react visual tests
* fix: add missing dependency @superdoc/common for layout-bridge
* fix: update visual test snapshots
|
Would love to see this merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue where
vite-plugin-node-polyfillsfailed to resolve shim imports (likevite-plugin-node-polyfills/shims/process) from packages outside the workspace during the build phase.Problem
When building a project that imports packages from outside the main workspace (e.g., from a sibling workspace or monorepo package), Rollup would fail with:
This issue was reported in the reproduction case: https://github.com/Jinjiang/reproductions/tree/vite-polyfill-20251125
Root Cause
The
@rollup/plugin-injectplugin only provides atransformhook but not aresolveIdhook. When external packages reference Node.js globals (likeprocess,Buffer, orglobal), the inject plugin transforms them into import statements:However, without a
resolveIdhook, Rollup cannot resolve these imports when they're in packages outside the main workspace, causing the build to fail.Solution
Added a custom Rollup plugin called
vite-plugin-node-polyfills:shims-resolverthat provides aresolveIdhook to resolve shim imports. The plugin:require.resolve()The fix applies to all three global shims:
buffer,global, andprocess.Testing
Changes
shimsResolverPluginto handle resolveId for shim imports during build