Fix virtual module imports when the project path contains an apostrophe #18401

Closed
AirBorne04 opened 7:00pm on October 15, 2026 wanted to merge 1 commit into withastro/astro main from
fix/session-driver-quoted-path

Pull Request Overview

  • Opened on October 15, 2026
  • Status Closed
  • Commit count 1 with first commit October 15, 2026

Total Delta

0 Total Diff Delta

Open Days

Open 19 weekdays

Test Delta

0 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
 
0 days Authoring 1 commit before pull request opened for review
 
0 days Awaiting first review

Total time for pull request 0 business days from first commit to closed PR

Author avatar

Fix virtual module imports when the project path contains an apostrophe

Changes


  • Fixes a dev server 500 when the project path contains an apostrophe and a session driver is set, as @astrojs/node does by default. Astro writes the resolved driver path into the generated virtual:astro:session-driver module inside single quotes, so a path like ~/arc's site/ ends the string early and Vite can't parse the module.

  • The cache provider, middleware and src/fetch.ts modules break the same way. In dev, src/fetch.ts is then ignored without an error.

  • These import paths now go through JSON.stringify(), as the content layer already does. Paths without special characters resolve to the same files.

Reproduction with Astro 7.4.0 and @astrojs/node 11.1.8:

npm create astro@latest "arc's site" -- --template minimal --install --no-git --yes

cd "arc's site"
npx astro add node --yes
npx astro dev

Opening / returns a 500 and logs:

Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.

Stack trace:
at \0virtual:astro:session-driver:1:208

With pnpm and an on-demand page, astro build fails at the same module.

Testing


  • New test/units/virtual-module-imports.test.ts loads each of the four modules with an apostrophe in the resolved path and checks that the generated imports point at it. Without the fix, each case fails with a parse error.

Docs


  • None: bug fix, no API change.

Comments Threads Pending Resolution

Resolved Comment Threads

No resolved comments have been left on this PR.