running npm install
in my top-level workspace does not seem to create a node_modules directory in my nested workspace.
not sure! I am using npm@next-7
, in which "phase 1" of workspace support has been added according to this blog post, but I'm unable to find documentation as to what specifically has been done and what is still outstanding. Being pointed to documentation (or being told that none exists yet!) is the main goal of this issue.
$ mkdir root; cd root
$ npm init -y; npm install --save lodash
$ mkdir -p packages/foo
"workspaces": { "packages": [ "packages/*" ] },
as described by the RFC$ cd packages/foo ; npm init -y; npm install --save express; cd ../..
$ find . -name 'node_modules' | xargs rm -rf
npm install
in the root workspace: $ npm install
at this point, no node_modules
directory is present in the nested workspace.
thanks for any help you can provide!
I discovered it while debugging something in Arborist: the paths added to the namespaces
field (takes standard globs) will be symlinked to the root node_modules
folder, and commands like npm install
run in the root package will cascade through the workspace packages.
that's what i know so far. theres probalby more
that's what the RFC says should happen, yes. and that seems to be the case if package-lock.json in the root workspace contains a packages
field. following the steps above does not create such a field.
@orzechowskid you have to check in node-modules/.package-lock.json
. it's not in the other one
hi @orzechowskid! In the RFC page you linked originally there is an example showing the expected behavior (installing deps of workspaces into top-level node_modules
folder) which is actually quite similar to your example ๐
Here's the result example as taken from the RFC, (you can see it here in its context):
$ tree
.
โโโ package-lock.json
โโโ node_modules
โ โโโ lodash
โ โโโ libnpmutil -> ./core/libnpmutil
โ โโโ workspace-a -> ./packages/workspace-a
โ โโโ workspace-b -> ./packages/workspace-b
โ โโโ workspace-c -> ./packages/workspace-c
โ โโโ react
โโโ core
โ โโโ libnpmutil
โโโ packages
โโโ workspace-a
โโโ workspace-b
โโ worspace-c
โโโ node_modules
โโโ [email protected]
In the example above, it's possible to have a ./core/libnpmutil/index.js
that contains a require('lodash')
(so that you can cd ./core/libnpmutil
and node index.js
from there) and that require('lodash')
is going to work as expected, this is possible due to Node.js own module resolution that you can dig more in case you're curious about it.
Let me know if this is helpful enough and feel free to close the issue if that's the case ๐
I ran into a similar issue and I think it is related to #1762. The new npm configuration that contains the workspaces field appears to be ignored for me if there is an existing lockfile and the issue is that you are running npm install lodash
before adding a workspaces field. (Although I consider this a bug)
I got npm@7 to correctly create a workspace by first ensuring that all folders & package.json files were configured correctly, removing all node_modules & package-lock.json files and then running npm install in the workspace root.
I think it was a mistake on my part to include an example in my original report when all I was really looking for is documentation. I was attempting to follow the issue template and tried to make clear what I was asking for, but it seems like I did not do a very good job and for that I apologize.
if I can rephrase: how do I find out which features of npm workspaces are supported in the latest npm 7 betas and which are not, so I can file bugs against features that are supposed to work and be patient regarding features which are not?
if I can rephrase: how do I find out which features of npm workspaces are supported in the latest npm 7 betas and which are not, so I can file bugs against features that are supposed to work and be patient regarding features which are not?
oohh I see ๐ sorry I was really confused by the original post and replies.
so the one important thing to note here is that we still have some test and documentation work to wrap up after we're done with the beta ๐ so for now the best documentation available on what is supported really is that approved RFC that you linked originally. Anything not in there you may assume to not be supported for now (note: we already have an ongoing follow up RFC open to get feedback on implementing more workspaces features).
Hope this is more helpful now! ๐ Thanks for reaching out and helping us clarify that!
ahh, that makes sense, thank you. I will stick to what's in the RFC for now, and follow along with discussions in progress. thanks again.
For people reaching this via search engine, this RFC is the only documentation available at the moment...
I fell like the current documentation (RFC) is really lacking in real-life examples. If you're stuck like I was yesterday you can learn on my misconception of the npm's workspaces (they are not like yarn workspaces at all) and how to actually use them in my article Simplify your monorepo with npm 7 workspaces .
Most helpful comment
I fell like the current documentation (RFC) is really lacking in real-life examples. If you're stuck like I was yesterday you can learn on my misconception of the npm's workspaces (they are not like yarn workspaces at all) and how to actually use them in my article Simplify your monorepo with npm 7 workspaces .