Skip to content

fix(plugins): replace __dirname with ESM-compatible import.meta.url - #37

Merged
SoonIter merged 2 commits into
rstackjs:mainfrom
buyfakett:fix/esm-dirname
Sep 18, 2026
Merged

SoonIter merged 2 commits into
rstackjs:mainfrom
buyfakett:fix/esm-dirname

Conversation

@buyfakett

Copy link
Copy Markdown
Contributor

Summary

  • The V2 upgrade (feat: upgrade to Rspress V2 #11) added "type": "module" to all packages but left __dirname usages in plugin sources, causing ReferenceError: __dirname is not defined when the built ESM plugins are loaded (e.g. via jiti when loading rspress.config.ts):
    ReferenceError: __dirname is not defined
        at rspressPluginGoogleAnalytics (dist/index.js:16:26)
    
  • Derive __dirname from import.meta.url via path.dirname(fileURLToPath(import.meta.url)) in the 7 affected packages: google-analytics, vercel-analytics, back-to-top, file-tree, live2d, mermaid, reading-time
  • Add a changeset (patch for all 7 packages)

Test plan

  • pnpm build for all 7 packages succeeds; dist output contains the ESM-compatible derivation
  • Loading rspress-plugin-google-analytics/dist/index.js in Node ESM no longer throws and globalUIComponents resolves correctly
  • Run rspress dev in a downstream project with the patched plugin

buyfakett and others added 2 commits September 18, 2026 11:33
The V2 upgrade (dade6fb) added "type": "module" to all packages but left
`__dirname` usages in place, which throws `ReferenceError: __dirname is
not defined` when the built ESM plugins are loaded (e.g. via jiti in
rspress.config.ts). Derive the directory from import.meta.url instead.

Affected packages: google-analytics, vercel-analytics, back-to-top,
file-tree, live2d, mermaid, reading-time.
@buyfakett

Copy link
Copy Markdown
Contributor Author

pls merge and release, thx

@SoonIter
SoonIter merged commit 20196b7 into rstackjs:main Sep 18, 2026
2 checks passed
@buyfakett

Copy link
Copy Markdown
Contributor Author

@SoonIter pls release packages

@SoonIter

Copy link
Copy Markdown
Member

@SoonIter pls release packages

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants