unocss: UnoCSS cannot work on Astro when version >= 65.5.0
UnoCSS version
65.5.0
Describe the bug
$ astro dev
(node:14840) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Then the error log:
node:internal/modules/esm/load:208
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
^
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:208:11)
at defaultLoad (node:internal/modules/esm/load:103:3)
at ModuleLoader.load (node:internal/modules/esm/loader:739:12)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:519:43)
at #createModuleJob (node:internal/modules/esm/loader:543:36)
at #getJobFromResolveResult (node:internal/modules/esm/loader:312:34)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:280:41)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:582:25) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
Node.js v23.7.0
error: script "dev" exited with code 1
Reproduction
- Minimal example that has upgrade unocss >= 65.5.0: https://github.com/cworld1/astro-unocss-test
- Minimal example that can work well: https://github.com/cworld1/astro-unocss-test/tree/efc050f81262d8bafdfaaf2c9487ce562bf72d31
System Info
Astro v5.3.0
Node v23.7.0
System Windows (x64)
Package Manager bun/pnpm
Output static
Adapter none
Integrations none
Validations
- Read the Contributing Guidelines.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 15 (12 by maintainers)
Commits related to this issue
- ci: run unit test on windows avoid issue https://github.com/unocss/unocss/issues/4441 — committed to antfu-collective/unconfig by sxzz 2 years ago
- fix: upgrade & unpin `unconfig` closes #4441 — committed to sxzz/unocss by sxzz 2 years ago
- fix: upgrade & unpin `unconfig` closes #4441 — committed to sxzz/unocss by sxzz 2 years ago
The error when resolving UnoCSS config file via
unconfig::createConfigLoaderat@unocss/configpackage. It works with node 20.10.0 LTS but fails with node 23.8.0: this line is failing https://github.com/unocss/unocss/blob/main/packages-engine/config/src/index.ts#L59You can force using previous
unconfigversion via “resolutions” or “pnpm.overrides” (latest UnoCSS using latestunconfigversion that’s using node 23 insteadjitito load the configuration): you will need to check when previous change was included atunconfigand use the proper version.The issue should be fixed when my PR at
unconfigmerged and released.https://github.com/antfu-collective/unconfig/pull/40
@userquin I’m also using node 23 but not sure if they are related. Please try this reduced test case. 🙏
In the meantime, you can add
shell-emulator=trueto.npmrcfile and use this script (pnpm only, other package managers will require using cross-env):ok, found the problem, with node 23 we’re not using jiti to load ts config file, we’re using dynamic import directly, so we need to normalize the path before loading the module (
uno.config.ts) here (we need to use a valid url via href):https://github.com/antfu-collective/unconfig/blob/main/src/index.ts#L148-L150