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

@aws-cdk/aws-lambda-nodejs: bundling fails when adding a workspace or file to nodeModules list #17830

Closed
joshbalfour opened this issue Dec 3, 2021 · 2 comments · Fixed by #17851
Assignees
Labels
@aws-cdk/aws-workspaces Related Amazon WorkSpaces bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@joshbalfour
Copy link

joshbalfour commented Dec 3, 2021

First off, thanks for all the work you all do on CDK, I have so many good things to say about it, it really is the future of IaC ❤️
This might be an edge case, but I really want to get aws-lambda-nodejs working for us, when it is it'll make our cdk setup super sleak!
I'll figure out a workaround and update the issue when I do, and hopefully be able to actually contribute towards a solution.

What is the problem?

We have a monorepo setup with all our packages in a packages directory.
When I have a dependency listed in the nodeModules attribute of bundling which is in our workspace
The generated package.json looks like this:

{"dependencies":{"espree":"7.3.1","@reapit/app-builder":"workspace:packages/app-builder"}}

and the yarn install --no-immutable which runs in the bundling-temp directory fails with:

➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: @reapit/app-builder@workspace:packages/app-builder: Workspace not found (@reapit/app-builder@workspace:packages/app-builder)
    at ie.getWorkspaceByDescriptor (/Users/joshbalfour/src/foundations/.yarn/releases/yarn-2.4.2.cjs:2:360510)
    at n.getCandidates (/Users/joshbalfour/src/foundations/.yarn/releases/yarn-2.4.2.cjs:2:408948)
    at n.getCandidates (/Users/joshbalfour/src/foundations/.yarn/releases/yarn-2.4.2.cjs:2:342946)
    at n.getCandidates (/Users/joshbalfour/src/foundations/.yarn/releases/yarn-2.4.2.cjs:2:342946)
    at /Users/joshbalfour/src/foundations/.yarn/releases/yarn-2.4.2.cjs:2:364602
    at Module.w (/Users/joshbalfour/src/foundations/.yarn/releases/yarn-2.4.2.cjs:2:424073)
    at C (/Users/joshbalfour/src/foundations/.yarn/releases/yarn-2.4.2.cjs:2:364565)
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 63ms

When I try to use the same package with file instead of workspace the generated package.json looks like this:

{"dependencies":{"espree":"7.3.1","@reapit/app-builder":"file:../app-builder"}}

and the yarn install --no-immutable which runs in the bundling-temp directory fails with:

➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: @reapit/app-builder@file:../app-builder::locator=root-workspace-0b6124%40workspace%3A.: ENOENT: no such file or directory, lstat '/Users/joshbalfour/src/foundations/packages/app-builder-backend/cdk.out/app-builder'
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 100ms

It works fine when using normal packages from the registry.

Reproduction Steps

I've created a stripped-down monorepo which reproduces this. It's a bit big because of the .yarn/cache folder, sorry.

What did you expect to happen?

The workspace/file packages referenced in my package.json should be installed correctly for my bundled code.

What actually happened?

It errored, as above.

CDK CLI Version

1.134.0

Framework Version

No response

Node.js Version

v14.18.1

OS

macOS Monterey 12.0.1

Language

Typescript

Language Version

4.3.5

Other information

full stack trace:

/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/core/lib/asset-staging.ts:398
      throw new Error(`Failed to bundle asset ${this.node.path}, bundle output is located at ${bundleErrorDir}: ${err}`);
            ^
Error: Failed to bundle asset cloud-foundations-app-builder-backend/graphql/Code/Stage, bundle output is located at /Users/joshbalfour/src/foundations/packages/app-builder-backend/cdk.out/bundling-temp-945296717e7e756e9c8781e96618fcf8a2c031e882066df54ce9b0b2c98ee49e-error: Error: bash -c yarn run esbuild --bundle "/Users/joshbalfour/src/foundations/packages/app-builder-backend/src/lambda.js" --target=node14 --platform=node --outfile="/Users/joshbalfour/src/foundations/packages/app-builder-backend/cdk.out/bundling-temp-945296717e7e756e9c8781e96618fcf8a2c031e882066df54ce9b0b2c98ee49e/index.js" --external:aws-sdk --external:espree --external:@reapit/app-builder && echo '{"dependencies":{"espree":"7.3.1","@reapit/app-builder":"file:../app-builder"}}' > /Users/joshbalfour/src/foundations/packages/app-builder-backend/cdk.out/bundling-temp-945296717e7e756e9c8781e96618fcf8a2c031e882066df54ce9b0b2c98ee49e/package.json && cp /Users/joshbalfour/src/foundations/yarn.lock /Users/joshbalfour/src/foundations/packages/app-builder-backend/cdk.out/bundling-temp-945296717e7e756e9c8781e96618fcf8a2c031e882066df54ce9b0b2c98ee49e/yarn.lock && cd /Users/joshbalfour/src/foundations/packages/app-builder-backend/cdk.out/bundling-temp-945296717e7e756e9c8781e96618fcf8a2c031e882066df54ce9b0b2c98ee49e && yarn install --no-immutable run in directory /Users/joshbalfour/src/foundations exited with status 1
    at AssetStaging.bundle (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/core/lib/asset-staging.ts:398:13)
    at AssetStaging.stageByBundling (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/core/lib/asset-staging.ts:246:10)
    at stageThisAsset (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/core/lib/asset-staging.ts:137:35)
    at Cache.obtain (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/core/lib/private/cache.ts:24:13)
    at new AssetStaging (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/core/lib/asset-staging.ts:162:44)
    at new Asset (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/aws-s3-assets/lib/asset.ts:84:21)
    at AssetCode.bind (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/aws-lambda/lib/code.ts:183:20)
    at new Function (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/aws-lambda/lib/function.ts:341:29)
    at new NodejsFunction (/Users/joshbalfour/src/foundations/packages/app-builder-backend/node_modules/@aws-cdk/aws-lambda-nodejs/lib/function.ts:53:5)
    at Object.createFunction (/Users/joshbalfour/src/foundations/packages/app-builder-backend/cdk/components/function.ts:12:10)
Subprocess exited with error 1
@joshbalfour joshbalfour added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2021
@github-actions github-actions bot added the @aws-cdk/aws-workspaces Related Amazon WorkSpaces label Dec 3, 2021
jogold added a commit to jogold/aws-cdk that referenced this issue Dec 5, 2021
…ules`

If the dependency version is a `file:`, find its absolute path so that
we can install it in the temporary bundling folder.

Closes aws#17830
@jogold
Copy link
Contributor

jogold commented Dec 5, 2021

@joshbalfour the file: case can easily be solved, see #17851. For the workspace: case I'm not sure...

@mergify mergify bot closed this as completed in #17851 Dec 6, 2021
mergify bot pushed a commit that referenced this issue Dec 6, 2021
…ules` (#17851)

If the dependency version is a `file:`, find its absolute path so that
we can install it in the temporary bundling folder.

Closes #17830


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Dec 6, 2021

⚠️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.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…ules` (aws#17851)

If the dependency version is a `file:`, find its absolute path so that
we can install it in the temporary bundling folder.

Closes aws#17830


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-workspaces Related Amazon WorkSpaces bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants