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

Failed to resolve entry for package when use react + vite #18931

Closed
2 of 4 tasks
dfiai opened this issue Aug 31, 2023 · 9 comments
Closed
2 of 4 tasks

Failed to resolve entry for package when use react + vite #18931

dfiai opened this issue Aug 31, 2023 · 9 comments
Assignees

Comments

@dfiai
Copy link

dfiai commented Aug 31, 2023

Current Behavior

I create 2 packages app and lib using react/vite, I got build app error when import lib in to the app.

Expected Behavior

Lib should be referenced in the app without errors.

GitHub Repo

No response

Steps to Reproduce

  1. create 2 packages using nx/react/vite app and lib
    image

  2. add import lib in the app
    image

  3. npx nx build my-app: [commonjs--resolver] Failed to resolve entry for package "my-lib". The package may have incorrect main/module/exports specified in its package.json.

It was reproducible in ubuntu and windows , magically after renaming one of the package it started to work but after npm i, it stopped again

Nx Report

Node   : 16.16.0
   OS     : win32-x64
   npm    : 8.11.0

   nx                 : 16.7.4
   @nx/js             : 16.7.4
   @nx/jest           : 16.7.4
   @nx/linter         : 16.7.4
   @nx/workspace      : 16.7.4
   @nx/devkit         : 16.7.4
   @nx/eslint-plugin  : 16.7.4
   @nx/react          : 16.7.4
   @nrwl/tao          : 16.7.4
   @nx/vite           : 16.7.4
   @nx/web            : 16.7.4
   typescript         : 5.1.6

Failure Logs

No response

Package Manager Version

8.11.0

Operating System

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

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: react Issues related to React support for Nx label Aug 31, 2023
@steven10172
Copy link

Related to #18492 (comment)

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Mar 18, 2024
@dbehmoaras
Copy link

I am running into the exact same issue

@github-actions github-actions bot removed the stale label Mar 31, 2024
@MBelniak
Copy link

MBelniak commented Apr 3, 2024

Has anyone tried enabling this option? https://vitejs.dev/config/shared-options#resolve-preservesymlinks
It helped in my case (the path to main was being referenced from resolved location instead of path in node_modules)

@Coly010
Copy link
Contributor

Coly010 commented May 17, 2024

Hi! Could you please provide a repo with a minimal reproduction so that I can investigate this further?

Copy link

This issue has been automatically marked as stale because no reproduction was provided within 7 days.
Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue.
Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues.
This issue will be closed in 21 days if a reproduction is not provided.
If a reproduction has been provided, please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label May 25, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2024
@Wurielle
Copy link

Wurielle commented Jun 28, 2024

Has anyone tried enabling this option? https://vitejs.dev/config/shared-options#resolve-preservesymlinks It helped in my case (the path to main was being referenced from resolved location instead of path in node_modules)

I just tried this but it didn't work for me although I found what's causing the issue in the process.

The issue only appeared when I added workspaces in my root package.json file.
Something about Vite aliases generated by nxViteTsPaths + the fact that the packages are already present within node_modules (due to workspaces) breaks the module resolution for Vite.

I haven't found a solution for my problem except by manually setting resolve.alias in my vite.config.ts for each package.
Setting resolve.preserveSymlinks = true doesn't change anything for me.

Edit:

After more fiddling I noticed resolveId from the nxViteTsPaths plugin is never called probably because Vite already resolved it

resolveId(importPath: string) {

As suggested in the issue under the link, adding enforce: 'pre' in node_modules/@nx/vite/plugins/nx-tsconfig-paths.plugin.js after name: 'nx-vite-ts-paths', solves the issue for me.

I'm using npx patch-package @nx/vite for now with "postinstall": "npx patch-package" under my scripts in my root package.json if anyone is looking for a solid fix on their version of nx

@kristianmandrup
Copy link

Hi @Wurielle do you have a gist or repo to look at which demonstrates this configuration?
Would I just need to insert "postinstall": "npx patch-package" in my root package.json?

Copy link

github-actions bot commented Aug 2, 2024

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 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants