Im looking for help with basic lib dependency in an app. not a custom solution
Nx monorepo: Internal library imports not found after production build
I'm working in an Nx monorepo (v20.4.4) with a Node.js app called pulse. The app builds and runs fine in development (nx serve pulse), but in production, it fails with Cannot find module errors for internal libraries.
Folder structure (simplified):
apps/
pulse/
src/
main.ts
libs/
shared/
mongo-connect/
src/
index.ts
Problem:
When I build the app:
nx build pulse
And try to run it:
node dist/apps/pulse/main.js
I get this error:
Error: Cannot find module '/.../node_modules/@readyfastcode/mongo-connect/src/index.js'.
Please verify that the package.json has a valid "main" entry
The output JS includes lines like: (code from dist that is failing)
module.exports = require("@readyfastcode/mongo-connect");
But @readyfastcode/mongo-connect is an internal lib — it's not published and doesn’t exist in node_modules. If I change the path to a relative one (like ../../libs/shared/mongo-connect/src/index.js), it works, but that’s not maintainable.
i saw others using transform paths but why? this is supposed to work without
i see suggestions to update apps/pulse/project.json with dependsOn or implicitDependencies. from what i tried that doesnt change anythin.
My environment:
- Nx:
20.4.4 - @nx/node:
20.4.4 - @nx/js:
20.8.1 - Node:
20.9
Question:
Im not looking for a custom solution. just looking for basic NX functionality. The relation ship between apps and libs is the whole point of nx. Im looking for a lesson or documentation or a debug route
Is there a clean way to either bundle the app or resolve internal lib paths like @readyfastcode/mongo-connect at runtime, without publishing them or rewriting import paths?
Any help would be appreciated!