Skip to content

obuild --stub generates absolute Windows paths, causing ERR_UNSUPPORTED_ESM_URL_SCHEME #50

@blouflashdb

Description

@blouflashdb

Environment

OS: Windows 11
Node.js: v24.5.0
Package Manager: pnpm
obuild version: 0.2.1

Reproduction

  1. Set up a monorepo structure on Windows. (e.g., using pnpm workspaces).

    /monorepo
      /packages
        /my-lib         <-- Package to be stubbed
      /apps
        /my-nuxt-app    <-- Consuming application
    
  2. Configure my-lib to use obuild for stubbing.

    packages/my-lib/package.json:

    {
      "name": "my-lib",
      "version": "1.0.0",
      "main": "./dist/index.mjs",
      "module": "./dist/index.mjs",
      "types": "./dist/index.d.mts",
      "exports": {
        ".": {
          "import": "./dist/index.mjs",
          "types": "./dist/index.d.mts"
        }
      },
      "scripts": {
        "dev": "obuild --stub"
      },
      "devDependencies": {
        "obuild": "latest"
      }
    }

    packages/my-lib/build.config.ts:

    import { defineBuildConfig } from 'obuild/config'
    
    export default defineBuildConfig({
      entries: [
        'src/index'
      ],
    })

    packages/my-lib/src/index.ts:

    export const message = "Hello from stubbed lib!";
  3. Run the stub command from the root of the monorepo.

    pnpm --filter my-lib run dev
  4. Inspect the generated stub file. The output file packages/my-lib/dist/index.mjs will contain an absolute Windows path:

    // packages/my-lib/dist/index.mjs
    // ⚠️ PROBLEM: This path is not a valid ESM import on Windows
    export * from "C:/Users/YourUser/Projects/monorepo/packages/my-lib/src/index.ts";
  5. Attempt to use my-lib from my-nuxt-app. The Nuxt dev server will fail during module resolution.

    Error Output:

    Error: 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 'c:'
    ...
    code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
    

Describe the bug

When using obuild's stub mode (obuild --stub) within a monorepo workspace on Windows, the generated stub file for a package re-exports the source code using an absolute Windows file path (e.g., C:/...).

This absolute path is not a valid file:// URL. When another package in the workspace (like a Nuxt or Vite application) tries to import from this stubbed package, Node.js's ESM loader fails with an ERR_UNSUPPORTED_ESM_URL_SCHEME error because it interprets C: as an unsupported URL protocol.

This effectively makes stub mode unusable on Windows for local development within a workspace.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions