fix: eliminate Node.js path dependencies in client-side code#30
fix: eliminate Node.js path dependencies in client-side code#30rsp2k wants to merge 1 commit intoFevol:mainfrom
Conversation
…ent code The plugin was causing Vite warnings about "Module path has been externalized for browser compatibility" because client-side code was importing micromatch, which depends on picomatch, which uses node:path. Changes: - Create sitemap/browser-utils.ts with pure JavaScript utilities safe for browsers - Add isGlobMatch() and firstMatchingPatternBrowser() as lightweight alternatives to micromatch for client-side glob matching - Add joinUrlPath() for browser-safe URL path joining (replaces node:path.join) - Update preprocess-sitemap.ts to use browser-safe glob matching - Update Astro components to split imports: firstMatchingPattern from util.ts (server-side only), other utils from browser-utils.ts - Update all client-side TypeScript to import from browser-utils.ts This eliminates the "Cannot access path.sep in client code" warnings and ensures clean browser console output during development.
|
EDIT: Sorry, I misread the first part of your message. After some more investigation, it is sensible to split up the functionality into |
What's the problem?
In dev mode, the console fills up with warnings like:
The graph renders briefly then disappears. Root cause:
preprocess-sitemap.tsimportsmicromatch, which pulls inpicomatch→node:path. Browsers don't havenode:path, so Vite stubs it out and things break.The fix
Created
sitemap/browser-utils.tswith pure JS alternatives:isGlobMatch()/firstMatchingPatternBrowser()- regex-based glob matching (replaces micromatch for client code)joinUrlPath()- string-based path joiningUpdated all client-side files to import from
browser-utils.ts. Server-side Astro frontmatter can still use the fullmicromatchviautil.ts.Tested
No breaking changes - just swapping out the internals.