Fix ESM resolver fallback for pnpm symlinked dependencies#207
Merged
Conversation
When using wds with ESM mode in pnpm workspaces, module resolution was failing for symlinked peer dependencies (e.g., graphql from graphql-ws). The oxc-resolver would fail to resolve these modules and immediately throw an error, preventing fallback to Node's built-in resolver. Changed the resolution logic to gracefully handle oxc-resolver failures by allowing the code to continue to Node's native resolver, which properly handles pnpm's symlink structure. The resolver now follows this cascade: 1. Try oxc-resolver (for TypeScript extension aliasing) 2. On failure, fall back to Node's native resolver (handles symlinks) 3. On failure, fall back to CommonJS require This allows ESM mode to work correctly with pnpm workspaces while maintaining the TypeScript resolution capabilities that oxc-resolver provides. Fixes issue where "Cannot find module 'graphql'" errors occurred despite the module being properly installed in pnpm's .pnpm directory.
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.
Fix ESM resolver fallback for pnpm symlinked dependencies
Problem
When using
wdswith ESM mode (esm: true) in pnpm workspaces, module resolution fails for symlinked peer dependencies. For example, trying to importgraphqlfrom withingraphql-wsresults in:Workaround: Setting
esm: falseresolves the issue because the CJS hook uses Node's nativerequire()resolution which handles pnpm symlinks correctly.Root Cause
The bug was in
child-process-esm-loader.ts(lines 80-83). When oxc-resolver failed to resolve a module, it immediately threw an error instead of falling back to Node's built-in resolver:This prevented the existing fallback logic (lines 103-129) from ever running.
Solution
Restructured the resolution logic to gracefully handle oxc-resolver failures: