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

System Info

Astro                    v5.3.0
Node                     v23.7.0
System                   Windows (x64)
Package Manager          bun/pnpm
Output                   static
Adapter                  none
Integrations             none

Validations

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

The error when resolving UnoCSS config file via unconfig::createConfigLoader at @unocss/config package. 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#L59

You can force using previous unconfig version via “resolutions” or “pnpm.overrides” (latest UnoCSS using latest unconfig version that’s using node 23 instead jiti to load the configuration): you will need to check when previous change was included at unconfig and use the proper version.

The issue should be fixed when my PR at unconfig merged and released.

@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=true to .npmrc file and use this script (pnpm only, other package managers will require using cross-env):

"dev": "NODE_OPTIONS=--no-experimental-strip-types astro dev",

Image

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