-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Nuxt module dependencies are not inherited from layers #26980
Comments
Isn't this behavior expected?
So in your layer, you would install anything that is needed by the host project as a |
@adamdehaven Yeah, true it might be intentional, but I think some discussion is required on how to handle cases where dev dependencies actually do need to be inherited by the main app - for example, Nuxt modules. In my repro, the This seems to be a recurring issue with other Nuxt modules as well (here, here, and here, all these instances, people are trying to use modules), so I don't think it's an issue with the tailwind module specifically. Clearly this is a case where some dev dependencies are necessary, but others might be undesirable. I'm not really sure how we would differentiate, to be honest. Unless we said "modules are special, modules are inherited as dev dependencies but all other dev dependencies are not"? Just to completely address your comment here:
Adding Maybe I jumped the gun calling this a "bug", but I think it needs discussion, because right now, it seems installing modules in a layer will make that layer unusable. |
As I understand them, most of the IMO, this falls on the layer author to know that they are building a layer rather than an app, and to have the dependencies specified accordingly (meaning moving any required packages from This follows the same pattern as using any other npm package: if your package has required dependencies, they must either be declared as
Simply moving |
Doesn't seem to work I'm afraid, unless I set it up wrong? Repro'd here - https://github.com/Brads3290/nuxt-layer-devependency-repro/tree/repro-runtimedep. Here's what I did:
Result:
I did also try the same with I'll admit that I'm just getting the hang of the npm ecosystem (I'm a .NET guy myself), so there may be something simple I'm missing here - hopefully not, otherwise I've wasted everyone's time. |
I only see a lock file in app directory, meaning it doesn't look like you installed dependencies for your layer directory? If you're treating each directory as a standalone "package" you'll need to install dependencies in both. The tailwind module isn't anywhere to be found in the lock file in the app directory. |
@adamdehaven ah, the package-lock.json is gitignored in the layer directory but not the app directory, for some reason. Must be a difference in the default templates. I have
On that note, that seems to differ from the behaviour I observed in the working example for traditional runtime dependencies (e.g.
I'd say this is exactly what the repro demonstrates - the tailwind module isn't being included in the app, despite it being a dependency of a layer that the app extends. |
@adamdehaven I can't replicate those results, and to the best of my knowledge, I did exactly as you suggested. Which branch of my repository did you use? I linked to the If there was any confusion there, that's my fault for confusing things with multiple branches - sorry about that. Here's my terminal, in a completely fresh directory so I'm working from the same code as you (except I suspect you might not have been on the same branch). Some output omitted for brevity.
Note in my Good point about |
I believe the issue you're running into now (on the If your layer was truly a separately published package, I don't believe you'd be having the issue (but maybe @manniL or someone can confirm my suspicion). If you properly set up
{
"name": "project-name",
"workspaces": [
"nuxt-app",
"nuxt-layer"
]
}
Your project should now run successfully (except there's an unrelated issue described below). Separately, I see you have this WARN Cannot extend config from {"install":true} in /Users/adam/Desktop/nuxt-layer-devependency-repro/nuxt-app Since the layer is not a git remote source, you need to exclude the extends: ['../nuxt-layer'] |
@adamdehaven Yes! That seems to work! Thank you very much for your patience, I really appreciate it. So I guess my question now is - is that something you'd expect someone to know, if they're familiar with npm? In other words, is my unfamiliarity with the environment the root cause here? I'm just wondering if there's a way we can make this a little easier for someone coming along next time. From my perspective, the situation kind of went like this:
I feel like I looked at a fair bit of documentation and examples before diving into this (e.g. the Nuxt layers documentation, which also links to this video, also this, and @manniL's video here), and nothing really indicated that in order to use modules with layers, they had to be part of a workspace. The closest was @manniL's video which defined a workspace file, but had no mention of it's relevance - he just used it to show the structure of his project (or at least, that's how I interpreted it). To me, layers seemed to be an "it just works" way of extracting common parts of a Nuxt app into reusable parts, and there's no way I would have figured out that they needed to be part of a workspace if it wasn't for your help. All the examples seem to treat local layers as "just another directory". All that to say, from my perspective I think this needs to be documented a bit better. What do you think? |
A couple of other thoughts/observations:
Edit: I also checked that Muhammad added |
Layers are essentially reusable "things" across projects - this is the piece I think you got confused on. From the docs:
You were treating your If you reference the quote from the docs above:
This is true; however, you also have to properly "prepare" and consume the layers.
This is actually incorrect as your layer package would never work in an external repository (its
I use a similar layer structure in several projects and the published, standalone layers do work correctly 😄 |
Ok, thanks again for your help with this. Noted on all points above.
I think monorepo was the key word I missed there, because I didn't realise that with npm you need to set up a monorepo in a specific way -- using workspaces. I just assumed it was a repo containing all your packages - assumptions, assumptions 🤦♂️ Do you think that's worth spelling out a bit more in the docs? For someone coming in from another stack, that's very easy to miss, but maybe it's ubiquitous amongst npm users?
Ok, good to know - thanks! I might have a look at Muhammad's repro and see if I can figure out where it deviates from what you've said, just to make sure my understanding is solid. I think this issue can be closed, but could you please let me know if you think it's worth opening a documentation request? I'd be happy to submit a PR to add this info to the docs if they're open sourced. |
Just wondering - do you host your layers on GitHub, or npm? I can get external layers to work via npm, but for the life of me I can't get them to work via GitHub if they have module dependencies! |
Hi @Brads3290 have you managed to find a workaround for this yet? I don't want to go the monorepo route |
@jbiddulph I didn't, I'm sorry. I can get it to work with monorepo and with external npm packages, but not with GitHub. I closed this issue since the original question is answered, but gave up getting GitHub dependencies to install. |
@jbiddulph and @Brads3290 Perhaps it was because of this bug? #26479 Looks like the fix is merged, but has yet to be released. Looks like it will be in |
Environment
Darwin
v20.11.1
-
3.11.1
-
yarn@1.22.15
-
-
-
-
Reproduction
https://github.com/Brads3290/nuxt-layer-devependency-repro/tree/repro
Describe the bug
UPDATE: I incorrectly assumed this is an issue with dev dependencies, but as @adamdehaven pointed out, "dev dependencies not being inherited" is expected. The actual issue is that modules used by the layer are not inherited by the main app. This happens even when they are specified as runtime dependencies in the layer.
When using a Nuxt layer, dev dependencies are not installed in the consumer of the layer (e.g. the main app).
Copied my explanation from the repro README here. I've provided a branch (
working
) with a working example of inheriting layer dependencies (where runtime dependencies are inherited), and another branch (repro
) where we attempt to inherit dev dependencies (the tailwindcss Nuxt module), but they aren't inherited by the app.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: