(aws-lambda-nodejs): does not properly detect `esbuild` when used with Yarn 2+ in PnP mode
See original GitHub issueaws-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:
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:
- Created 3 years ago
- Reactions:3
- Comments:24 (17 by maintainers)
#14914
Just report I got
error Command "esbuild" not found.
under yarn v1.22.10 and cdk 1.106.1 (build c832c1b)