question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-lambda-nodejs): does not properly detect `esbuild` when used with Yarn 2+ in PnP mode

See original GitHub issue

aws-cdk in general works properly with yarn 2+ in Plug’n’Play (PnP) mode. See https://yarnpkg.com/features/pnp

PnP mode does not use node_modules and thus npx cannot detect that esbuild is installed in the project, so this block of code fails:

https://github.com/aws/aws-cdk/blob/8f1cfe4087b765cecd3ceb01745167646d617fec/packages/%40aws-cdk/aws-lambda-nodejs/lib/util.ts#L115-L130

Also this block of code is problematic as well since it also uses npx: https://github.com/aws/aws-cdk/blob/8f1cfe4087b765cecd3ceb01745167646d617fec/packages/%40aws-cdk/aws-lambda-nodejs/lib/bundling.ts#L141-L158

Overall, spawning esbuild via its CLI seems far less than ideal. Instead, it should probably be executed via its nodejs api:

Example:

require('esbuild').buildSync({
  entryPoints: ['in.ts'],
  outfile: 'out.js',
})

Getting the installed version would be as easy as: require('esbuild/package.json').version

Reproduction Steps

mkdir test
yarn init -2
...set up cdk project...
yarn add esbuild

yarn cdk deploy '*'

Prints: esbuild cannot run locally. Switching to Docker bundling.

A workaround is possible by installing esbuild globally, but this is far from ideal.

What did you expect to happen?

esbuild should work properly

What actually happened?

esbuild cannot run locally. Switching to Docker bundling.

Environment

  • CDK CLI Version : 1.90.1
  • Framework Version: 1.90.1
  • Node.js Version: 15.9.0
  • OS : macOS
  • Language (Version): TypeScript 4.0.5

Other

Originally added in https://github.com/aws/aws-cdk/pull/11289 by @jogold


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:24 (17 by maintainers)

github_iconTop GitHub Comments

6reactions
jogoldcommented, May 28, 2021
6reactions
titanjercommented, May 27, 2021

Just report I got error Command "esbuild" not found. under yarn v1.22.10 and cdk 1.106.1 (build c832c1b)

Read more comments on GitHub >

github_iconTop Results From Across the Web

@aws-cdk/aws-lambda-nodejs | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
r/javascript - Yarn 3.0 - Performances, ESBuild, Better Patches
I've migrated a project and found that all its dependencies could handle Yarn 2 with nodeLinker: "node-modules" and the only thing blocking me ......
Read more >
Yarn 3.0 Performances, ESBuild, Better Patches, ... - Yarnpkg
When using Yarn 3 w/ PnP, the exports field will be properly resolved regardless of your Node version. If you're not familiar with...
Read more >
How to fix problems with esbuild in Yarn - DEV Community ‍ ‍
js so that dependencies are resolved using .pnp.cjs if yarn is configured to use PnP. 2 ...
Read more >
Source - GitHub
baseUrl() does not return FIPS-compliant url for gov cloud regions ... **lambda-nodejs:** esbuild detection with Yarn 2 in PnP mode ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found