Skip to content

astro/check thinks typescript is not installed when using TypeScript 7 #17268

Closed

Description

@robertbaker

Astro Info

Astro                    v7.0.5
Node                     v24.18.0
System                   Windows (x64)
Package Manager          bun
Output                   static
Adapter                  none
Integrations             fix-mdx-astro7
                         @astrojs/mdx
                         astro-icon

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Need to be compatible with TS 7. Currently it think ts is not installed and prompts to install it. Run npm run check or astro check to see the problem.

What's the expected result?

It works and doesn't prompt to install typescript

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-eatjhone?file=package.json

Participation

  • I am willing to submit a pull request for this issue.
Pinned by ematipico

Activity

  1. astrobot-houston commented on Jul 2, 2026

    @astrobot-houston
    Contributor
    • Reproduced: Yes
    • Exploration: Yes — View branch
    • Unit Test: Yes — packages/astro/test/units/cli/install-package.test.ts
    • Priority: P4: important. This completely breaks astro check for anyone using TypeScript 7, with no workaround other than downgrading TypeScript.

    The getPackage() function in packages/astro/src/cli/install-package.ts uses require.resolve(packageName) to detect whether a package is installed. TypeScript 7 removed its default CJS export entry point (no main field and no . in its exports map), so require.resolve('typescript') throws ERR_PACKAGE_PATH_NOT_EXPORTED instead of resolving. The catch block treats all errors as "package not installed," which is incorrect for this case.

    I found a potential fix for this issue. When require.resolve() throws ERR_PACKAGE_PATH_NOT_EXPORTED, the fix falls back to resolving ${packageName}/package.json to confirm the package is actually installed, and returns a truthy value instead of falling through to the install prompt.

    Try this fix

    You can test this fix right now without waiting for a release:

    npm i https://pkg.pr.new/astro@fdec70e
    

    If this fixes your issue, please leave a comment letting us know (e.g. "confirmed, this fixes it"). We'll then open a pull request to get this merged.

    Full Triage Report

    Issue #17268: astro/check thinks typescript is not installed when using TypeScript 7

    Original Issue

    Title: astro/check thinks typescript is not installed when using TypeScript 7
    Author: robertbaker
    URL: #17268

    Description: When using TypeScript 7 (v7.0.1-rc), running astro check thinks TypeScript is not installed and prompts to install it.

    Environment from issue:

    • Astro v7.0.5
    • Node v24.18.0
    • Windows (x64)
    • Package Manager: bun

    Reproduction Result — ✅ Successfully Reproduced

    Steps to Reproduce:

    1. Create a project with astro and typescript@7.0.1-rc as dependencies
    2. Run astro check

    Actual Result:

    $ astro check
    To continue, Astro requires the following dependency to be installed: typescript.
    [ERROR] [check] The `@astrojs/check` and `typescript` packages are required for this command to work.
    

    Expected Result: astro check should recognize TypeScript 7 as installed and run diagnostics normally.

    Root Cause

    File: packages/astro/src/cli/install-package.ts, getPackage() function (lines 25-31)

    TypeScript 7 removed its default CJS export. Its exports map only contains sub-path exports like ./unstable/sync and ./package.json — no . entry. This causes require.resolve('typescript') to throw ERR_PACKAGE_PATH_NOT_EXPORTED instead of MODULE_NOT_FOUND. The catch block in getPackage() treats ALL errors as "package not installed," conflating "can I import this?" with "is this installed?".

    The typescript value returned by getPackage() in check/index.ts is never used as a module — it's only checked for truthiness (if (!typescript)). The function is being used purely as an "is this installed?" check.

    Verdict: Bug (high confidence)

    No code comments, prior issues, or design rationale suggest this was intentional. The catch-all catch {} was introduced by a lint cleanup commit, not a deliberate design choice. The scenario of a package being installed but having no default export was simply never considered.

    Fix

    File changed: packages/astro/src/cli/install-package.ts

    When require.resolve() throws ERR_PACKAGE_PATH_NOT_EXPORTED, the fix falls back to resolving ${packageName}/package.json. If that succeeds, the package is confirmed installed and a truthy {} is returned.

    -\t} catch {
    +\t} catch (e) {
    +\t\tif ((e as NodeJS.ErrnoException)?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
    +\t\t\ttry {
    +\t\t\t\trequire.resolve(`${packageName}/package.json`, {
    +\t\t\t\t\tpaths: [options.cwd ?? process.cwd()],
    +\t\t\t\t});
    +\t\t\t\treturn {} as T;
    +\t\t\t} catch {
    +\t\t\t\t// Fall through to install prompt
    +\t\t\t}
    +\t\t}

    Verification: Before fix → error. After fix → Result (4 files): 0 errors, 0 warnings, 0 hints ✅
    Unit test added in packages/astro/test/units/cli/install-package.test.ts. All 36 CLI tests pass.
    Changeset: .changeset/warm-results-drive.md — astro: patch

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  2. added
    triage: fix pending
    - P4: important
    pkg: astro
    on Jul 2, 2026
  3. robertbaker commented on Jul 2, 2026

    @robertbaker
    Author

    @astrobot-houston no, still getting the prompt that typescript is not installed. need to patch @astrojs/check too

  4. added
    triage: fix rejected
    and removed
    triage: fix pending
    on Jul 2, 2026
  5. matthewp commented on Jul 2, 2026

    @matthewp
    Contributor

    @robertoms99 we fixed a similar issue yesterday (not released), can you test this?

    npm i https://pkg.pr.new/astro@aab01cb
    
  6. self-assigned this
    on Jul 2, 2026
  7. added
    triage: needs triage
    and removed
    triage: fix rejected
    on Jul 2, 2026
  8. astrobot-houston commented on Jul 2, 2026

    @astrobot-houston
    Contributor
    • Reproduced: Yes
    • Exploration: Yes — View branch
    • Unit Test: Yes — packages/astro/test/units/cli/install-package.test.ts
    • Priority: P4: important. This completely breaks astro check for anyone using TypeScript 7, with no workaround other than downgrading TypeScript.

    TypeScript 7 removed its default CJS entry point (no . in its exports map), so require.resolve('typescript') throws ERR_PACKAGE_PATH_NOT_EXPORTED instead of resolving. This affects two locations: getPackage() in packages/astro/src/cli/install-package.ts (which treats all errors as "not installed") and require.resolve('typescript') in packages/language-tools/astro-check/src/index.ts (which crashes when constructing AstroCheck). The previous fix only addressed the first location — the user confirmed the second location also needs patching.

    I found a potential fix for this issue. The fix handles ERR_PACKAGE_PATH_NOT_EXPORTED in both astro core and @astrojs/check by falling back to resolving typescript/package.json, and adds a loadTypeScript() fallback in the language server. The @astrojs/check peerDependencies are also updated to include ^7.0.0.

    Try this fix

    You can test this fix right now without waiting for a release:

    npm i https://pkg.pr.new/astro@2add254
    

    Note: This preview only includes the astro core package. The @astrojs/check changes (resolving TypeScript path and peerDependencies update) are included in the branch but not in this preview build. If you're using pnpm, the astro fix alone may be sufficient since @astrojs/check can resolve TypeScript via module resolution.

    If this fixes your issue, please leave a comment letting us know (e.g. "confirmed, this fixes it"). We'll then open a pull request to get this merged.

    Full Triage Report

    Issue #17268: astro/check thinks typescript is not installed when using TypeScript 7

    Original Issue

    Title: astro/check thinks typescript is not installed when using TypeScript 7
    Author: robertbaker
    URL: #17268

    Description: When using TypeScript 7 (v7.0.1-rc), running astro check thinks TypeScript is not installed and prompts to install it.

    Environment from issue:

    • Astro v7.0.5
    • Node v24.18.0
    • Windows (x64)
    • Package Manager: bun

    Reproduction Result — ✅ Successfully Reproduced

    Steps to Reproduce:

    1. Create a project with astro and typescript@7.0.1-rc as dependencies
    2. Run astro check

    Actual Result:

    $ astro check
    To continue, Astro requires the following dependency to be installed: typescript.
    [ERROR] [check] The `@astrojs/check` and `typescript` packages are required for this command to work.
    

    Expected Result: astro check should recognize TypeScript 7 as installed and run diagnostics normally.

    Root Cause

    TypeScript 7 removed its default CJS export entry point. Its package.json has \"type\": \"module\" and an exports map with only subpath exports (./unstable/sync, ./package.json, etc.) — no . entry. This causes require.resolve('typescript') to throw ERR_PACKAGE_PATH_NOT_EXPORTED.

    Two locations in the codebase are affected:

    1. packages/astro/src/cli/install-package.ts (line 28): getPackage() uses require.resolve() to detect installation. The catch-all block treats ERR_PACKAGE_PATH_NOT_EXPORTED as "not installed" — conflating "can I import this?" with "is this installed?"

    2. packages/language-tools/astro-check/src/index.ts (line 28): require.resolve('typescript') is called to get the TypeScript path for the AstroCheck constructor. This also throws with TS7.

    Verdict: Bug (high confidence)

    The catch-all catch {} in install-package.ts was introduced by a lint cleanup commit (4c1b769bcf0, chore: bump typescript-eslint to v8), not a deliberate design choice. The require.resolve('typescript') in @astrojs/check was added during the Volar 2 upgrade (15a5532) with no consideration for packages lacking a . export. No prior issues or PRs discuss intentionally excluding TypeScript 7.

    Fix

    Files changed:

    1. packages/astro/src/cli/install-package.ts — When require.resolve() throws ERR_PACKAGE_PATH_NOT_EXPORTED, fall back to resolving ${packageName}/package.json. If that succeeds, the package is installed — return {} as T.

    2. packages/language-tools/astro-check/src/index.ts — Wrap require.resolve('typescript') in try/catch. On ERR_PACKAGE_PATH_NOT_EXPORTED, resolve typescript/package.json and derive the package directory path.

    3. packages/language-tools/language-server/src/check.ts — Extract TypeScript loading into loadTypeScript() with fallback resolution and a clear error message.

    4. packages/language-tools/astro-check/package.json — Updated peerDependencies to \"^5.0.0 || ^6.0.0 || ^7.0.0\".

    Verification: Before fix → error. After fix → Result (4 files): 0 errors, 0 warnings, 0 hints ✅
    Regression check: TS6 still works ✅
    Unit test added in packages/astro/test/units/cli/install-package.test.ts. All 36 CLI tests pass and all 6 @astrojs/check tests pass.
    Changeset: .changeset/upset-owls-dance.md — astro: patch, @astrojs/check: patch

    Note on full TS7 compatibility: In pnpm setups, @volar/kit resolves TypeScript from its own module context (typically TS6), so the check toolchain works. In flat node_modules (npm) where only TS7 is available, the language server and volar stack may need further updates since TS7 has a completely restructured API.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  9. added
    triage: fix pending
    and removed
    triage: needs triage
    on Jul 2, 2026
  10. 41 remaining items

  11. Princesseuh commented on Sep 4, 2026

    @Princesseuh
    Member

    Just to give a progress report since I know many people are following this issue, here's where we stand:

    Once all is said and done, you'll be able to install the Astro Content Mapper:tm: into your project, and just run tsc to check Astro files with TS7 and benefit from TypeScript 7 in the editor. astro check will either be deprecated, or be updated to call tsc or something like that.

  12. Princesseuh commented on Sep 17, 2026

    @Princesseuh
    Member

    An update on this:

    In the editor, #17852 is still needed to land before there's full support, but, it's a bit clumsy to support right now anyway since 7.1 is still far from release. Nonetheless, I hope to land it soon!

  13. added a commit that references this issue on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- P4: importantecosystem: upstreampkg: astropkg: language-toolstriage: unable to fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions