You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Secondary entry-point package.json files in APF require mainFields resolution (in Vitest) #45326
area: packagingIssues related to Angular's creation of npm packagesneeds reproductionThis issue needs a reproduction in order for the team to investigate further
Which @angular/* package(s) are the source of the bug?
core, router, Don't known / other
Is this a regression?
No - but not sure
Description
I'm trying to get unit test working with vite test. I've ran into an issue when importing testing modules
Error: Failed to resolve entry for package "@angular/core/testing". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@angular/core/testing". The package may have incorrect main/module/exports specified in its package.json.
This also applies to the router module.
Please provide a link to a minimal reproduction of the bug
Thanks for this issue @Jordan-Hall. I would be happy to look into this. Looking at the current exports being generated in our package.json, I can see ./testing being declared properly with the expected conditions.
In your repository, what would be the steps to reproduce the issue? I assume just test, but it's always good to be explicit when a reproduction is provided (saving some time)
Not sure if these conditions are valid Native Node conditions? Maybe you should have “import” as a fallback as the last condition? Although it has default condition, which I guess should be a fallback 🤔
Thanks for the update @Jordan-Hall. @sheremet-va: Yes, some conditions are custom to allow the Angular CLI/or users to have more control over which output flavor they prefer. Custom conditions are totally valid.
As you said, the default condition should match here ("import") should not be needed). After some investigation I figured out why this error surfaces:
Angular libraries (including the official packages) expose secondary package.json files for TypeScript resolution. e.g. node_modules/@angular/core/testing/package.json. This will be the package.json picked up for the resolution.
These secondary package.json files do not have exports defined since these are not at the package top-level.
Vitest seems to have the mainFields for non-exports resolution set to an empty array (only looking for main since this loop will never run)
Adding an explicit mainFields resolution setting, fixes the issue.
FWIW: I want to remove these secondary package.json files (Angular Package Format v13 was a step towards this), but currently this is not a planned task. I might get to it indirectly when refactoring some things for better d.ts bundling.
changed the title [-]@angular/core/testing: The package may have incorrect main/module/exports specified in its package.json[/-][+]Secondary entry-point `package.json` files in APF require `mainFields` resolution[/+]on Mar 20, 2022
changed the title [-]Secondary entry-point `package.json` files in APF require `mainFields` resolution[/-][+]Secondary entry-point `package.json` files in APF require `mainFields` resolution (in Vitest)[/+]on Mar 20, 2022
area: packagingIssues related to Angular's creation of npm packagesneeds reproductionThis issue needs a reproduction in order for the team to investigate further
Activity
devversion commentedon Mar 11, 2022
Thanks for this issue @Jordan-Hall. I would be happy to look into this. Looking at the current
exportsbeing generated in ourpackage.json, I can see./testingbeing declared properly with the expected conditions.https://github.com/angular/core-builds/blob/master/package.json#L25
In your repository, what would be the steps to reproduce the issue? I assume just
test, but it's always good to be explicit when a reproduction is provided (saving some time)devversion commentedon Mar 11, 2022
The reproduction does fail in the
npm installsince your lock file seems to rely on a local registry (using e.g. verdaccio).Jordan-Hall commentedon Mar 20, 2022
Hey @devversion https://github.com/Jordan-Hall/vite-angular-template this should be a better test repo. Sorry it's taken so long wanted next beta release off the compiler to be release.
sheremet-va commentedon Mar 20, 2022
Not sure if these conditions are valid Native Node conditions? Maybe you should have “import” as a fallback as the last condition? Although it has default condition, which I guess should be a fallback 🤔
devversion commentedon Mar 20, 2022
Thanks for the update @Jordan-Hall. @sheremet-va: Yes, some conditions are custom to allow the Angular CLI/or users to have more control over which output flavor they prefer. Custom conditions are totally valid.
As you said, the
defaultcondition should match here ("import") should not be needed). After some investigation I figured out why this error surfaces:package.jsonfiles for TypeScript resolution. e.g.node_modules/@angular/core/testing/package.json. This will be thepackage.jsonpicked up for the resolution.package.jsonfiles do not haveexportsdefined since these are not at the package top-level.mainFieldsfor non-exports resolution set to an empty array (only looking formainsince this loop will never run)mainFieldsresolution setting, fixes the issue.e.g.
devversion commentedon Mar 20, 2022
FWIW: I want to remove these secondary
package.jsonfiles (Angular Package Format v13 was a step towards this), but currently this is not a planned task. I might get to it indirectly when refactoring some things for betterd.tsbundling.[-]@angular/core/testing: The package may have incorrect main/module/exports specified in its package.json[/-][+]Secondary entry-point `package.json` files in APF require `mainFields` resolution[/+][-]Secondary entry-point `package.json` files in APF require `mainFields` resolution[/-][+]Secondary entry-point `package.json` files in APF require `mainFields` resolution (in Vitest)[/+]devversion commentedon Apr 22, 2022
Closing as this is not an issue with Angular. I provided a workaround, and the issue is now mitigated with the upcoming v14
angular-automatic-lock-bot commentedon May 23, 2022
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.