Open arizonatribe opened 2 years ago
I was tinkering around a bit this morning and discovered something that might help pin down the issue. Basically it seems that nx
isn't looking at a packages/
folder the same way it's looking at a libs/
or apps/
folder.
In those Steps to Reproduce I described, you'll end up with a packages/scalars/
folder and a project.json
properly configured. However the output for nx build scalars
or nx test scalars
indicates that nx
isn't finding that project.json
. Although adding in a workspace.json
to the root of the repo can fix it, that isn't the point.
The experiment was I created a libs/
folder and copied the packages/scalars/
into it as-is. And NX was able to find it and execute the nx test scalars
just fine.
So it seems that the underlying cause might be the packages/
directory isn't one of the few that NX checks when there is no workspace.json
. Does that help?
Follow-up to the follow-up :smile:
Looking through the source code the devkit
package seems the schema for the nx.json
file defines this:
/**
* Where new apps/libs should be placed
*/
workspaceLayout: {
libsDir: string;
appsDir: string;
}
When I set my nx.json
like this it works:
"workspaceLayout": {
"libsDir": "packages"
}
However the default workspace preset for an NX generated NPM lib should have that same setting. It seems that it might not be read-in early enough (or everywhere it's needed) in @nrwl/tao
. I think that would be the spot for the fix.
Summary
NX is not able to locate project/packages in a monorepo to which it was added (via this
add-nx-to-monorepo
generator).Details
The
add-nx-to-monorepo
recently removed the scaffolding of theworkspace.json
, however the latestnx
CLI doesn't (yet) seem to be able to recognize nested packages/projects without that file.The
workspace.json
did make it so that project names can be mapped to folder locations in a monorepo, however this is likely consolidated now into thenx.json
.My expectation was the
nx
CLI was modified so that it would be able to recognize projects without that explicit mapping (probably traversing folders and searching for nestedpackage.json
and/orproject.json
files?). However the latest version ofnx
doesn't seem to be able to locate projects without it.I did update to the latest of
nx
(viayarn global upgrade
) and confirmed afterwards it's the latest vianpm view nx
.Steps to Reproduce
To reproduce easily, here is a public, open-source repository I've been migrating from Lerna to NX (feel free to clone and use):
I'll outline the steps I took and hopefully will make it easier for you to assist or give me any homework.
package-lock.json
andnode_modules/
-rm -rf node_modules package-lock.json
yarn
and create the lock file-yarn install
npx add-nx-to-monorepo
yarn add --dev @nrwl/js
yarn nx g @nrwl/js:lib scalars --buildable
nx test scalars
ornx build scalars
Questions
I'm not sure if there is an issue with this generator or with NX or rather if there's a mistake I'm making which you can help point out. Maybe I even need to open/move this issue to another repo. Regardless, I'm happy to assist or create a PR if you can point me in the right direction.
These are my (speculation) questions:
nx.json
now to replace the project mapping previously located in theworkspace.json
? If so, is it possible this generator just needs to be updated to do it too?nx
CLI to accommodate the deprecation of theworkspace.json
?NX version: 13.4.1 Yarn version: 1.22.0 Node version: v14.17.0 OS version: Fedora v35