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] Bundle fails on 1.58 due to incorrect path. #9709

Closed
thantos opened this issue Aug 14, 2020 · 1 comment · Fixed by #9724
Closed

[@aws-cdk/aws-lambda-nodejs] Bundle fails on 1.58 due to incorrect path. #9709

thantos opened this issue Aug 14, 2020 · 1 comment · Fixed by #9724
Assignees
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p1

Comments

@thantos
Copy link
Contributor

thantos commented Aug 14, 2020

This is similar to #9673. Though I think that specific error can be resolved by clearing the output cache.

Synth/Deploy fails when using NodeJSFunction on 1.58. Project synthed and deployed fine on 1.56.

Reproduction Steps

Upgraded to 1.58 with NodeJSFunction.

const forwarderFunction = new NodejsFunction(this, 'myFunction', {
  entry: 'lib/functions/myFunction/index.ts',
  handler: 'handler',
});

cdk synth

What did you expect to happen?

Bundle NodeJSFunction code and synth.

What actually happened?

At first I received:

../../../../asset-output/index.js    4.3 KB    738ms
mv: ‘/asset-output/index.js’ and ‘/asset-output/index.js’ are the same file

Tried to change the name of my entry point

const forwarderFunction = new NodejsFunction(this, 'myFunction', {
  entry: 'lib/functions/myFunction/index2.ts',
  handler: 'handler',
});

cdk synth

Bundling asset MyStack/myFunction/Code/Stage...
Building index2.ts...
Bundling...
🚨 Build failed.
Error: ENOENT: no such file or directory, stat '/asset-input/lib/functions/myFunction/index.ts'
Error: ENOENT: no such file or directory, stat '/asset-input/lib/functions/myFunction/index.ts'

Same error as #9673. Notice that this is the old path. Deleted /.cdk.staging, cdk.out, .parcel-cache.

cdk synth

Bundling asset MyStack/myFunction/Code/Stage...
Building index2.ts...
Bundling...
Packaging index.js...
Optimizing index.js...
✨ Built in 3.21s

../../../../asset-output/index.js    4.3 KB    743ms
mv: cannot stat ‘/asset-output/index2.js’: No such file or directory

Notice it is looking for index2.js and not index.js.

Environment

  • CLI Version : 1.58.0
  • Framework Version: 1.58.0
  • Node.js Version: 10.19.0
  • OS : Windows 10 - WSL 2 - Ubuntu 20.04 - Docker version 19.03.12, build 48a66213fe
  • Language (Version): TypeScript (3.8.3) -->

Other

It looks like NodeJSFunction or assets are confusing the file name of the entry point with the computed /asset-output/index.js. Using an entry point called index.ts has a different error than when the entry point is named something unique. I am also curious if the folder depth matters, but it doesn't seem to since I already am 4 layers deep.


This is 🐛 Bug Report

@thantos
Copy link
Contributor Author

thantos commented Aug 14, 2020

Made it another step further.

Deleting the (auto-generated) cdk-lambda entries from the package.json allows index2.ts to succeed.

  "cdk-lambda": "/asset-output/index.js",
  "targets": {
    "cdk-lambda": {
      "context": "node",
      "includeNodeModules": {
        "aws-sdk": false
      },
      "sourceMap": false,
      "minify": false,
      "engines": {
        "node": ">= 10"
      }
    }
  }

However, all of the targets I have called index.ts fail with the error:

../../../../asset-output/index.js    5.72 KB    665ms
mv: ‘/asset-output/index.js’ and ‘/asset-output/index.js’ are the same file

the offending change it appears: d9723bb

Looks like all of the tests in aws-lambda-nodejs test for entry.ts and not index.ts.

entry: '/project/folder/entry.ts',

jogold added a commit to jogold/aws-cdk that referenced this issue Aug 14, 2020
Do not rename the dist file if it's already named `index.js`.

Fixes aws#9709
@eladb eladb added p1 effort/small Small work item – less than a day of effort labels Aug 17, 2020
@mergify mergify bot closed this as completed in #9724 Aug 17, 2020
mergify bot pushed a commit that referenced this issue Aug 17, 2020
…9724)

Do not rename the dist file if it's already named `index.js`.

Fixes #9709


----

*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-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants