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-lambda-nodejs doesn't build if parcel is not installed globally #6204

Closed
mattsains opened this issue Feb 10, 2020 · 9 comments · Fixed by #6206
Closed

aws-lambda-nodejs doesn't build if parcel is not installed globally #6204

mattsains opened this issue Feb 10, 2020 · 9 comments · Fixed by #6206
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. management/devenv Related to CDK development/build environment response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@mattsains
Copy link
Contributor

I think because of this line, parcel needs to be installed globally for aws-lambda-nodejs to build.

Reproduction Steps

  1. Take a working app containing a aws-lambda-nodejs construct.

  2. Run npm remove -g parcel

  3. Run cdk synth on the app. The command fails with:

    Failed to build file at ./lambda/src/index.ts: Error: spawnSync parcel ENOENT

Error Log

See above

Environment

  • **CLI Version : 1.22.0 (build 309ac1b)
  • **Framework Version: 1.23.0
  • **OS : MacOS 10.15.3
  • **Language : typescript

Other

I think you need to reference the binary as a dependency, similar to how npx works, rather than invoking spawn


This is 🐛 Bug Report

@mattsains mattsains added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 10, 2020
@mattsains
Copy link
Contributor Author

I think it might be possible to replace the code with the following:

const args = [
  'parcel',
  'build', options.entry,
  '--out-dir', options.outDir,
  '--out-file', 'index.js',
  '--global', options.global,
  '--target', 'node',
  '--bundle-node-modules',
  '--log-level', '2',
  !options.minify && '--no-minify',
  !options.sourceMaps && '--no-source-maps',
  ...options.cacheDir
    ? ['--cache-dir', options.cacheDir]
    : [],
].filter(Boolean) as string[];

const parcel = spawnSync('npx', args);

@SomayaB SomayaB added the package/tools Related to AWS CDK Tools or CLI label Feb 10, 2020
@SomayaB SomayaB added the management/devenv Related to CDK development/build environment label Feb 10, 2020
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Feb 10, 2020
@SomayaB
Copy link
Contributor

SomayaB commented Feb 10, 2020

Hi @mattsains, thanks for reporting this and opening up a PR, much appreciated! 👍

@SomayaB SomayaB added @aws-cdk/aws-lambda Related to AWS Lambda and removed needs-triage This issue or PR still needs to be triaged. labels Feb 10, 2020
@SomayaB SomayaB assigned nija-at and unassigned shivlaks Feb 10, 2020
@eladb
Copy link
Contributor

eladb commented Feb 12, 2020

@jogold can you take a look please?

@jogold
Copy link
Contributor

jogold commented Feb 12, 2020

@mattsains parcel shouldn't be installed globally after installing @aws-cdk/aws-lambda-nodejs locally, did you install @aws-cdk/aws-lambda-nodejs globally?

Can you run npm list -g --depth 0 after installing @aws-cdk/aws-lambda-nodejs locally?

@jogold
Copy link
Contributor

jogold commented Feb 12, 2020

I agree that there's maybe something to do to improve cross platform compatibility here but I'm not sure I would go with npx (there is a reinstall/redownload risk with npx). How about looking up the path of the bin and then run node <binPath> ...?

@nija-at nija-at added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed package/tools Related to AWS CDK Tools or CLI in-progress This issue is being actively worked on. labels Feb 12, 2020
@mattsains
Copy link
Contributor Author

@mattsains parcel shouldn't be installed globally after installing @aws-cdk/aws-lambda-nodejs locally, did you install @aws-cdk/aws-lambda-nodejs globally?

Can you run npm list -g --depth 0 after installing @aws-cdk/aws-lambda-nodejs locally?

Sorry, I think you might be misunderstanding me. I in fact didn't have parcel installed globally, that is the problem. Because the construct is calling spawn, it requires that parcel is installed globally in order for it to work - it's basically trying to execute parcel on $PATH.

I have not installed @aws-cdk/aws-lambda-nodejs globally either.

I agree that there's maybe something to do to improve cross platform compatibility here but I'm not sure I would go with npx (there is a reinstall/redownload risk with npx). How about looking up the path of the bin and then run node <binPath> ...?

I don't think this is an "improve cross-platform" issue - have you tried the reproduction steps? Unless I'm missing something, this would be a problem anywhere you haven't installed parcel globally (ie., the majority of users)

@jogold
Copy link
Contributor

jogold commented Feb 12, 2020

No, I was not able to reproduce.

It runs on my machine with a local install of @aws-cdk/aws-lambda-nodejs. It also runs like that here in the CI and the tests are passing.

What am I missing? Can you give more details about your environment?

@mattsains
Copy link
Contributor Author

Here is my npm list -g --depth 0 output:

/usr/local/lib
├── aws-cdk@1.22.0
├── aws-es-kibana@1.0.8
├── aws-iam-proxy@0.1.11
├── lerna@3.19.0
├── npm@6.13.7
├── ts-node@8.6.2
├── UNMET PEER DEPENDENCY typescript@>=2.7
└── yarn@1.21.1

Could you post yours?

@jogold
Copy link
Contributor

jogold commented Feb 12, 2020

/home/jonathan/.nvm/versions/node/v12.13.1/lib
└── npm@6.12.1

I think that I'm starting to understand I'm using aws-cdk locally also and running it with yarn (this is comparable to what runs here in the CI).

Let's continue the discussion in the PR to find the right fix.

@mergify mergify bot closed this as completed in #6206 Feb 14, 2020
mergify bot pushed a commit that referenced this issue Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. management/devenv Related to CDK development/build environment response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants