Skip to content

Conversation

blouflashdb
Copy link

Resolves #50

When using `obuild --stub` on Windows, the generated stub file would re-export the source code using an absolute Windows file path (e.g., `C:/...`).

This absolute path is not a valid `file://` URL, causing Node.js's ESM loader to fail with an `ERR_UNSUPPORTED_ESM_URL_SCHEME` error when another package in the workspace tries to import from the stubbed package.

This commit fixes the issue by calculating a relative path from the stub file to the source file and using that in the `export` statement. This ensures that the generated path is valid on all operating systems.
@blouflashdb blouflashdb reopened this Aug 13, 2025
Copy link
Contributor

@gxres042 gxres042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You looking for unjs/pathe?

@blouflashdb
Copy link
Author

You looking for unjs/pathe?

No? Is there anything wrong with this PR?

@gxres042
Copy link
Contributor

Use pathe instead of node:path can resolve this issue easily. 😄

When using `obuild --stub` on Windows, the generated stub file would re-export the source code using an absolute Windows file path (e.g., `C:/...`).

This absolute path is not a valid `file://` URL, causing Node.js's ESM loader to fail with an `ERR_UNSUPPORTED_ESM_URL_SCHEME` error when another package in the workspace tries to import from the stubbed package.

This commit fixes the issue by using `pathe` to calculate a relative path from the stub file to the source file and using that in the `export` statement. This ensures that the generated path is valid on all operating systems.
When using `obuild --stub` on Windows, the generated stub file would re-export the source code using an absolute Windows file path (e.g., `C:/...`).

This absolute path is not a valid `file://` URL, causing Node.js's ESM loader to fail with an `ERR_UNSUPPORTED_ESM_URL_SCHEME` error when another package in the workspace tries to import from the stubbed package.

This commit fixes the issue by using `pathe` to calculate a relative path from the stub file to the source file and using that in the `export` statement. This ensures that the generated path is valid on all operating systems.
@blouflashdb
Copy link
Author

Use pathe instead of node:path can resolve this issue easily. 😄

It uses pathe now.

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.

obuild --stub generates absolute Windows paths, causing ERR_UNSUPPORTED_ESM_URL_SCHEME

2 participants