Skip to content

Conversation

@yjaaidi
Copy link
Contributor

@yjaaidi yjaaidi commented Nov 13, 2025

This fixes the following error:
'The entry point "vitest" cannot be marked as external'

by excluding vitest from the discovered dependencies handed to optimizeDeps.include

Closes #31745

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #31745

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

projectName,
projectSourceRoot: this.options.projectSourceRoot,
optimizeDepsInclude: this.externalMetadata.explicitBrowser,
optimizeDepsInclude: this.externalMetadata.explicitBrowser.filter(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add a comment here?

I think that ideally, we should filter out all entrypoints from explicitBrowser but I can't imagine any valid scenario other then the vitest package import.

* Allow `vitest` import in browser mode.
* @see https://github.com/angular/angular-cli/issues/31745
*/
export default async function (): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given we really need to run in browser mode to reproduce the bug, I had to install the packages so I went with an e2e.

Any narrower test would be over-specifying and not provide enough confidence.

@yjaaidi
Copy link
Contributor Author

yjaaidi commented Nov 13, 2025

I'm AFK, I guess that I just have to explicitly choose headless.
I'll do this later

@yjaaidi yjaaidi force-pushed the fix/allow-vitest-import branch from 749fc15 to 30352fc Compare November 13, 2025 11:44
Copy link
Member

@clydin clydin left a comment

Choose a reason for hiding this comment

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

This was fixed via #31781 as now only implicit external packages are included of which vitest is not.

The root cause is that Vitest is making a variety changes to the optimizeDeps option internally for browser mode. One of which was adding vitest to entries which then caused an issue if vitest was also added to includes. Oddly, it also appears to add it to excludes which one may assume would take priority over an includes element.

An additional test case would still be useful though.

@clydin clydin added target: rc This PR is targeted for the next release-candidate action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 13, 2025
@yjaaidi
Copy link
Contributor Author

yjaaidi commented Nov 13, 2025

This was fixed via #31781 as now only implicit external packages are included of which vitest is not.

The root cause is that Vitest is making a variety changes to the optimizeDeps option internally for browser mode. One of which was adding vitest to entries which then caused an issue if vitest was also added to includes. Oddly, it also appears to add it to excludes which one may assume would take priority over an includes element.

An additional test case would still be useful though.

Ah perfect! I saw the PR later and I was about to give it a try to see if it fixes it.
Oh! I remember the excludes gotcha. I remember scratching my head recently on it 😅

@yjaaidi yjaaidi force-pushed the fix/allow-vitest-import branch from ab242c5 to 19b1123 Compare November 13, 2025 16:01
@yjaaidi yjaaidi force-pushed the fix/allow-vitest-import branch from 19b1123 to ef66314 Compare November 13, 2025 16:07
@clydin clydin removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 13, 2025
@clydin clydin changed the title fix(@angular/build): allow 'vitest' import in browser mode test(@angular/build): add test with 'vitest' import in browser mode Nov 13, 2025
@clydin clydin added the action: merge The PR is ready for merge by the caretaker label Nov 13, 2025
@hybrist hybrist merged commit 7206032 into angular:main Nov 14, 2025
32 checks passed
@hybrist
Copy link
Contributor

hybrist commented Nov 14, 2025

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unit-test builder causes the following error: The entry point "vitest" cannot be marked as external

3 participants