Skip to content
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

(lambda-nodejs): add support for monorepos #18175

Closed
mikestopcontinues opened this issue Dec 25, 2021 · 17 comments · Fixed by #18216
Closed

(lambda-nodejs): add support for monorepos #18175

mikestopcontinues opened this issue Dec 25, 2021 · 17 comments · Fixed by #18216
Assignees
Labels
@aws-cdk/aws-lambda-nodejs effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p2

Comments

@mikestopcontinues
Copy link

What is the problem?

Rolling my codebase up in a monorepo, I found that trying to build a NodejsFunction, I get the following error:

Usage Error: Couldn't find a script named "esbuild".

I'm using the following settings in .yarnrc.yml, which hoists all my node_modules to my monorepo root:

nmMode: hardlinks-global
nodeLinker: node-modules

Reproduction Steps

Here's a repro.

What did you expect to happen?

I expected it to work.

What actually happened?

Usage Error: Couldn't find a script named "esbuild".

CDK CLI Version

2.3.0 (build beaa5b2)

Framework Version

2.3.0

Node.js Version

v14.18.1

OS

OSX 12.0.1 (21A559)

Language

Typescript

Language Version

4.5.4

Other information

Happy holidays! 😁

@mikestopcontinues mikestopcontinues added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 25, 2021
@ryparker ryparker added p1 needs-triage This issue or PR still needs to be triaged. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 28, 2021
@blimmer
Copy link
Contributor

blimmer commented Dec 29, 2021

I've encountered this error before, as well. It's a bit confusing, but you need to have esbuild in your root package.json file, not in your packages/aws/package.json file. I tested this on your repro repository and it works (see https://github.com/mikestopcontinues/cdk-mono-yarn-esbuild-issue/pull/1).

@blimmer
Copy link
Contributor

blimmer commented Dec 29, 2021

Proposed documentation update here: #18216

@mikestopcontinues
Copy link
Author

Really awesome, @blimmer. Thanks!

Gonna leave this open, as I think it still qualifies as a bug.

@corymhall corymhall added p2 and removed p1 needs-triage This issue or PR still needs to be triaged. labels Jan 20, 2022
@corymhall corymhall added feature-request A feature should be added or improved. effort/medium Medium work item – several days of effort and removed bug This issue is a bug. labels Jan 25, 2022
@corymhall corymhall changed the title (aws-lambda-nodejs): Yarn 3 monorepo with esbuild in root - Couldn't find a script named "esbuild" (lambda-nodejs): add support for monorepos Jan 25, 2022
@corymhall
Copy link
Contributor

I am unassigning and marking this issue as p2, which means that we are unable to work on this immediately.

We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.

@corymhall corymhall removed their assignment Jan 25, 2022
@mergify mergify bot closed this as completed in #18216 Jan 25, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@corymhall corymhall reopened this Jan 25, 2022
LukvonStrom pushed a commit to LukvonStrom/aws-cdk that referenced this issue Jan 26, 2022
Closes aws#18175 - see aws#18175 (comment) for details.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
Closes aws#18175 - see aws#18175 (comment) for details.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@rix0rrr rix0rrr closed this as completed Mar 21, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@vleandersson
Copy link

@mikestopcontinues would it be possible to spin up the repo again for solution inspiration? :)

@mikestopcontinues
Copy link
Author

@vleandersson It would take a little too long to gut the private stuff while preserving the useful bits. I don't use CDK pipelines because I started before they existed. I can offer some tips though:

  1. Create a package for shared CDK-related utils, structs, config, and types. Some of these should be the const names of stack outputs.
  2. Create a package that deploys shared infra. Output using your shared config constants
  3. Create packages for each of your apps with their own CDK deployments. Reference shared infra using those constants.

I'm happy to answer any other questions you have!

@vleandersson
Copy link

@mikestopcontinues what I am struggling with at the moment is that NodejsFunction is requiring a separate .lock file per package.json. Using Yarn v3 only one .lock file is created in the root folder instead of within each package in the monorepo. Is this something you came across and got a solution for?

@blimmer
Copy link
Contributor

blimmer commented Jul 15, 2022

I added info about the single lockfile to the docs: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs-readme.html#reference-project-architecture

From my experience, this works great for yarn monorepos!

@vleandersson
Copy link

Thanks for your input @blimmer and @mikestopcontinues !
I think I found the issue. It seems like either earlier versions of yarn was giving more open access to workspace dependencies or pnp creates this limitation for esbuild to operate from the root level. Using esbuild with yarn 3 (berry) and its recommended pnp setting I used yarns own plugin that adds support for pnp.

I'll have a look at adding some info on this in the docs as well once I have a final solution up :)

@vleandersson
Copy link

Related issue: evanw/esbuild#884

@vleandersson
Copy link

Issue raised with aws #21161

@blimmer
Copy link
Contributor

blimmer commented Jul 15, 2022

With yarn PnP see also #19452 . I've found it necessary to use the node-modules linker for now.

@vleandersson
Copy link

@blimmer yeah, I saw that. Great insights. Thanks! Sadly nodeLinker: node-modules will turn off pnp, but I guess we got to live with that till we get pnp support added 🤷

@madeline-k
Copy link
Contributor

Hi all, from this issue, it's not clear what the ask is for supporting monorepos with lambda-nodejs. They already are supported (at least to some extent). Closing this issue, just because it is not actionable in it's current state. Please open a new issue if you have requests for monorepo support.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants