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
Code line content in this commit was purged after it aged past our code retention window of two weeks for this repo. We have insufficient quota to grab the code content at this time, please try back later.

If you receive this message over several days, please consider adding more users to your account (whose quota we can use to grab commit content), or contact [email protected] with error #33NFNE
Diff Delta:
0
Classified as:  Bug Fix

AirBorne04's Description of Work

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.

6 total changed files
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
End of PR:
No additional context awaits in the abyss below