Skip to content

[@nx/js] Published libs are not working #31332

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

Open
1 of 4 tasks
gperdomor opened this issue May 25, 2025 · 2 comments
Open
1 of 4 tasks

[@nx/js] Published libs are not working #31332

gperdomor opened this issue May 25, 2025 · 2 comments
Assignees
Labels
priority: medium Medium Priority (not high, not low priority) scope: js type: bug

Comments

@gperdomor
Copy link
Contributor

gperdomor commented May 25, 2025

Current Behavior

The are two problems with libs...

  1. Not works inside workspace's next applications, this is described here: Problems with Next and internal libs #30714
  2. The second and most important issue IMO, occurs when you publish the library to the npm registry and tries to use it inside a next app, no matter if is in a new workspace or a next app created with create-next-app command, It just doesn't work.

This issue is to track the second one, but in both cases the issue is the same, the module can't be resolved

Image

Image

Expected Behavior

Packages just should works as expected

GitHub Repo

https://github.com/gperdomor/nx-next-issue

Steps to Reproduce

  1. Create an empty workspace
  2. Create a publishable library and publish to npm registry or verdaccio local registry
  3. Create a Next app using npc create-next-app command
  4. Install your published library
  5. Use the library in a page of your next app
  6. Run the next app

Nx Report

report

 NX   Report complete - copy this into the issue template

Node           : 22.15.1
OS             : darwin-x64
Native Target  : x86_64-macos
pnpm           : 10.11.0

nx (global)        : 21.1.2
nx                 : 21.1.2
@nx/js             : 21.1.2
@nx/eslint         : 21.1.2
@nx/eslint-plugin  : 21.1.2
@nx/next           : 21.1.2
@nx/vite           : 21.1.2
@nx/web            : 21.1.2
typescript         : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/vite/plugin
@nx/eslint/plugin
@nx/next/plugin
---------------------------------------
Cache Usage: 0.00 B / 93.15 GB

Failure Logs

Package Manager Version

pnpm 10.11.0

Operating System

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

Additional Information

The issue described in point 2, seems to be related with development property in package.json exports fields

"exports": {
  "./package.json": "./package.json",
  ".": {
    "development": "./src/index.ts", <------- THIS
    "types": "./dist/index.d.ts",
    "import": "./dist/index.js",
    "default": "./dist/index.js"
  }
},

If you install the lib from npm registry and open the node_modules folder, go to the package folder and removes that line from the package.json, and runs your app, then the app works without issues

For testing purposes I published this sample @gperdomor/sample-lib package from the above GitHub repo

@gperdomor
Copy link
Contributor Author

Hi @ndcunningham , let me know if you need something else or If I can help you with something 🙏🏻

@FrozenPandaz FrozenPandaz added scope: js priority: medium Medium Priority (not high, not low priority) labels May 31, 2025
@MatthieuLebigre
Copy link

I'm also having the same kind of issue (not with Next, just a regular TS librairie)
Once it's published and used in another project, the development entrypoint refers to TS files, which can be in conflict with current project ts configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium Medium Priority (not high, not low priority) scope: js type: bug
Projects
None yet
Development

No branches or pull requests

4 participants