Skip to content

feat: support absoluteJitiPath for stub mode#542

Merged
pi0 merged 6 commits into
unjs:mainfrom
BobbieGoede:fix/nested-jiti-import-failure
Jul 23, 2025
Merged

feat: support absoluteJitiPath for stub mode#542
pi0 merged 6 commits into
unjs:mainfrom
BobbieGoede:fix/nested-jiti-import-failure

Conversation

@BobbieGoede

Copy link
Copy Markdown
Contributor

Related

When a stubbed build is being imported using jiti (and if this import throws an error), jiti will attempt to import it again during which the relative jiti import will fail, hiding the underlying error with a different error: Cannot find module '(incorrect_path_to_jiti_here)' imported from (path_to_jiti_here).

Here's a minimal reproduction of the issue https://stackblitz.com/edit/github-haxspghd?file=build.config.mjs

I'm not sure if there are drawbacks to using an absolute path over a relative path, but since the generated jiti.import(resolvedEntry) also uses an absolute path I figure this shouldn't be an issue.

@pi0

pi0 commented Jul 23, 2025

Copy link
Copy Markdown
Member

Can we please have it behind a flag first?

@BobbieGoede

Copy link
Copy Markdown
Contributor Author

@pi0
I have added an option to opt into this change stubOptions: { jitiImportType: 'absolute' }, though it might as well be a boolean value. Important thing is, it will default to the original behavior.

Comment thread src/types.ts Outdated
Comment thread src/build.ts Outdated
Comment thread src/builders/rollup/stub.ts
Comment thread src/builders/rollup/stub.ts Outdated

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks ❤️

@pi0 pi0 changed the title fix: use absolute jiti import path in stub feat: support absoluteJitiPath for stub mode Jul 23, 2025
@pi0 pi0 merged commit 0d7d23f into unjs:main Jul 23, 2025
2 checks passed
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.

2 participants