Skip to content

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

Open
@gperdomor

Description

@gperdomor

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

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions