fix(typescript-vfs): resolve lib dir via getDefaultLibFilePath so re-export wrappers (@typescript/typescript6) work - #3646
Draft
Andrea (andrepav1) wants to merge 1 commit into
Conversation
…export wrappers work
createDefaultMapFromNodeModules located lib.*.d.ts via path.dirname(require.resolve("typescript")), the resolved entry file's directory. For the official @typescript/typescript6 TS 7 side-by-side wrapper (whose entry re-exports @typescript/old) that directory has no lib files, so the default map was built without the stdlib and the VFS later threw. Derive the lib dir from the compiler's getDefaultLibFilePath, which follows the re-export.
Andrea (andrepav1)
force-pushed
the
fix/vfs-lib-dir-reexport-wrapper
branch
from
September 3, 2026 21:37
d4fb442 to
e2ab0e7
Compare
|
|
||
| // Resolve the lib dir from the compiler, which follows re-export wrappers (e.g. @typescript/typescript6) | ||
| // to the real stdlib; require.resolve would point at the wrapper's own lib/, which has no lib.*.d.ts. | ||
| const ts = _ts ?? (require("typescript") as typeof import("typescript")) |
There was a problem hiding this comment.
Does this break browser uses?
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.
Problem
createDefaultMapFromNodeModulesfinds the bundledlib.*.d.tsviapath.dirname(require.resolve("typescript")).require.resolvereturns the resolved package's entry file, so for a re-export wrapper the directory it points at contains no lib files.This breaks with the official TypeScript 7.0 side-by-side package
@typescript/typescript6(npm i -D typescript@npm:@typescript/typescript6), whose entry ismodule.exports = require("@typescript/old"). The reallib.*.d.tslive in the nested@typescript/old/lib/, so the default map is built without the stdlib and the VFS later throws:Any tool that builds a program through
createDefaultMapFromNodeModules(e.g.@ark/attest) fails on a project using the TS 7 side-by-side setup.Fix
Derive the lib directory from the compiler's own
getDefaultLibFilePath, which resolves from the executing file path and so follows the re-export to where the stdlib actually lives, instead ofrequire.resolve:tsLibDirectoryoverride.@ark/attestinvokecreateDefaultMapFromNodeModules(compilerOptions)with neither_tsnortsLibDirectory.Notes
createFSBackedSystemfurther down has the samepath.dirname(require.resolve("typescript"))pattern; happy to fix it here too — left out to keep the change focused on the reported path.@typescript/typescript6@6.0.2:getDefaultLibFilePathreturns the@typescript/old(typescript@6.0.3) lib dir with all 108lib.*.d.ts.