Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vite][Yarn Workspace] Failed to resolve entry for package "xyz" #20520

Closed
1 of 4 tasks
bobalazek opened this issue Dec 1, 2023 · 5 comments · Fixed by #27155
Closed
1 of 4 tasks

[Vite][Yarn Workspace] Failed to resolve entry for package "xyz" #20520

bobalazek opened this issue Dec 1, 2023 · 5 comments · Fixed by #27155
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@bobalazek
Copy link

bobalazek commented Dec 1, 2023

Current Behavior

I am unable to build react libraries if they are dependent on another library.

I spent the whole afternoon yesterday trying to fix this, but I couldn't really get to the bottom of this. Clearly, I've tried to set those "main" and "exports" to ./src/index.js, but this didn't work either, which kind of makes sense, because the web-ui library does build and in the dist folder the index.js is actually in the same directory as package.json, so I couldn't wrap my head around why that is an issue.

Expected Behavior

Should build as expected

GitHub Repo

https://github.com/bobalazek/nx-issue-repro

Steps to Reproduce

  1. Clone the repo
  2. Run yarn to install dependencies
  3. Run yarn nx run-many --target=build --all to try to build the apps

Nx Report

Node   : 20.9.0
   OS     : darwin-arm64
   yarn   : 4.0.2
   
   nx                 : 17.1.3
   @nx/js             : 17.1.3
   @nx/jest           : 17.1.3
   @nx/linter         : 17.1.3
   @nx/eslint         : 17.1.3
   @nx/workspace      : 17.1.3
   @nx/cypress        : 17.1.3
   @nx/devkit         : 17.1.3
   @nx/eslint-plugin  : 17.1.3
   @nx/react          : 17.1.3
   @nrwl/tao          : 17.1.3
   @nx/vite           : 17.1.3
   @nx/web            : 17.1.3
   typescript         : 5.2.2

Failure Logs

yarn nx run-many --target=build --all
 
    ✔  nx run web:build:production (2s)

    ✖  nx run web-core:build:production
       vite v4.3.9 building for production...
✓ 2 modules transformed.
       
       [vite:dts] Start generate declaration files...
       ✓ built in 645ms
       [vite:dts] Declaration files built in 611ms.
       
       [commonjs--resolver] Failed to resolve entry for package "@nx-issue-repro/web-ui". The package may have incorrect main/module/exports specified in its package.json.
       
        >  NX   Failed to resolve entry for package "@nx-issue-repro/web-ui". The package may have incorrect main/module/exports specified in its package.json.
       
          Pass --verbose to see the stacktrace.
       
       
    ✔  nx run web-ui:build:production (4s)

 ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target build for 3 projects (4s)
 
    ✔    2/3 succeeded [0 read from cache]
 
    ✖    1/3 targets failed, including the following:
         - nx run web-core:build:production

Package Manager Version

Yarn v4.0.2

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@bobalazek bobalazek changed the title [commonjs--resolver] Failed to resolve entry for package "xyz". The package may have incorrect main/module/exports specified in its package.json when including one react library into another [Vite][Yarn Workspace] Failed to resolve entry for package "xyz" Dec 1, 2023
@AgentEnder AgentEnder added the scope: bundlers Issues related to webpack, rollup label Dec 1, 2023
@hailerity
Copy link

I’ve just got into this problem too and found out that the problem is because the library has a symbolic link in node_modules, I think it’s created automatically when the library is created. Remove the symbolic and problem is solved.

@bobalazek
Copy link
Author

bobalazek commented Dec 6, 2023

The hacky fix for me was setting main in package.json to ./src/index.ts, which was mentioned in this issue: #18492 (comment). It kind of worked, but other issues cropped up after that.

At the end, I decided to migrate the whole project to Turborepo instead.

@fsgreco
Copy link

fsgreco commented Jan 8, 2024

Hi @bobalazek I found a different solution in case you're interested: basically instead of removing the symbolic link, you need to change the import alias name on "paths" property inside tsconfig.base.json. It need to have a different alias from the name specified in the package.json. If you call it @nx-issue-repro/web-ui then try to change it inside tsconf file and use this last new alias to import it inside the app.

I explain this solution in more detail in this recent issue: #21030
I guess yarn is doing the same thing that npm, since it creates a symbolic link of the library inside the node-modules directory that generate some conflicts, I also saw that your project uses nxViteTsPaths too...

Please let me know in the comments in case you try this and works (I'm curios if this happens also using yarn, it seems to be the case).

@MBelniak
Copy link

MBelniak commented Apr 3, 2024

This might help, as it's most probably related to symlinks as @hailerity mentioned #18931 (comment)

FrozenPandaz pushed a commit that referenced this issue Jul 30, 2024
…#27155)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
In Yarn and PNPM Workspaces, the `nxViteTsPaths`'s `resolveId` is not
called because Vite has already tried to resolve the module.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Ensure the `nxViteTsPath`'s logic is run before vite's internal
resolver.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #20520

(cherry picked from commit 795f847)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants