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

cdk synth fails to resolve symlinks when staging assets as of 1.16.0 #4978

Closed
vertti opened this issue Nov 12, 2019 · 11 comments · Fixed by #5022
Closed

cdk synth fails to resolve symlinks when staging assets as of 1.16.0 #4978

vertti opened this issue Nov 12, 2019 · 11 comments · Fixed by #5022
Assignees
Labels
bug This issue is a bug. p1 package/tools Related to AWS CDK Tools or CLI

Comments

@vertti
Copy link

vertti commented Nov 12, 2019

❓ General Issue

The Question

After upgrading from 1.15.0 to 1.16.1, cdk synth command fails with:

Error: ENOENT: no such file or directory, symlink '../fast-xml-parser/cli.js' -> 'cdk.out/asset.046889af674a59f8c3e80adeeadca2bd0a4922e131160a62c280be1c0d15a097/node_modules/.bin/xml2js'

fast-xml-parser is a dependency I have under lib/resources/package.json used by a lambda function.

Any idea where those symlinks come from or what creates them? And how to clean them / regenerate them.

Also running cdk synth and then cdk diff again seems to remove the issue and diff says No differences. But I have same issue running jest for the tests for the lambda (same missing symlink warning). If I revert back to 1.15.0, both work.

Environment

  • CDK CLI Version: 1.16.1 (build 9a5a761)
  • OS: Ubuntu
  • Language: TypeScript

Other information

Error: ENOENT: no such file or directory, symlink '../fast-xml-parser/cli.js' -> 'cdk.out/asset.046889af674a59f8c3e80adeeadca2bd0a4922e131160a62c280be1c0d15a097/node_modules/.bin/xml2js'
    at Object.symlinkSync (fs.js:909:3)
    at Object.copyDirectory (/home/vertti/dev/kesko/k-ruoka-product-service/importers/ttp-importer/node_modules/@aws-cdk/assets/lib/fs/copy.ts:25:14)
    at Staging.synthesize (/home/vertti/dev/kesko/k-ruoka-product-service/importers/ttp-importer/node_modules/@aws-cdk/assets/lib/staging.ts:87:7)
    at Function.synth (/home/vertti/dev/kesko/k-ruoka-product-service/importers/ttp-importer/node_modules/@aws-cdk/core/lib/construct.ts:56:28)
    at App.synth (/home/vertti/dev/kesko/k-ruoka-product-service/importers/ttp-importer/node_modules/@aws-cdk/core/lib/app.ts:142:36)
    at process.App.process.once (/home/vertti/dev/kesko/k-ruoka-product-service/importers/ttp-importer/node_modules/@aws-cdk/core/lib/app.ts:121:45)
    at Object.onceWrapper (events.js:286:20)
    at process.emit (events.js:198:13)
    at process.EventEmitter.emit (domain.js:448:20)
    at process.emit (/home/vertti/dev/kesko/k-ruoka-product-service/importers/ttp-importer/node_modules/source-map-support/source-map-support.js:485:21)
@vertti vertti added the needs-triage This issue or PR still needs to be triaged. label Nov 12, 2019
@sousandrei
Copy link

Getting the same here.
I suspect is something related to yarn workspaces and their links. Are you using it?

@SomayaB SomayaB added bug This issue is a bug. package/tools Related to AWS CDK Tools or CLI labels Nov 12, 2019
@kennu
Copy link

kennu commented Nov 12, 2019

I'm seeing the same problem with a TypeScript Lambda (compiled to JavaScript) which has these dependencies installed with regular npm install:

"dependencies": {
  "@aws/dynamodb-data-mapper": "^0.7.3",
  "@aws/dynamodb-data-mapper-annotations": "^0.7.3",
  "node-fetch": "^2.3.0",
  "uuid": "^3.3.2"
}

Problems are caused uuid, which sets up a symlink as .bin/uuid => ../uuid/bin/uuid. When I delete the symlink manually, deployment works.

Also noteworthy that after a failed attempt, AWS CDK leaves an incomplete cdk.out/asset.xxx folder there. Next time you run it, deployment succeeds, but the folder doesn't contain node_modules, so the deployed Lambda function doesn't actually work.

@hanstf
Copy link

hanstf commented Nov 13, 2019

same problem here but after installing the lambda dependencies with npm install --no-bin-links then deployment works.

@eladb
Copy link
Contributor

eladb commented Nov 13, 2019

Suspected as p0 so tagging as such

@eladb eladb added the p0 label Nov 13, 2019
@vertti
Copy link
Author

vertti commented Nov 13, 2019

@sousandrei Nope, plain npm.

@kennu my typescript lambdas have just these deps:

  "dependencies": {
    "adm-zip": "0.4.13",
    "fast-xml-parser": "3.14.0",
    "lodash": "4.17.15"
  }

@hanstf is probably correct as my error message also references the cli.js which is that packages bin.

@chillitom
Copy link
Contributor

I have this same issue, the package causing issues is detect-libc.

I am running on a Linux container image but the project/stack directory and node_modules reside on a Windows host mounted volume. The error is related to symlinks which can be a bit funky under Windows, I imagine this is related.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Nov 13, 2019
@shivlaks
Copy link
Contributor

repro-ing the issue

@shivlaks
Copy link
Contributor

confirmed that this is an issue as of 1.16.0 - assets are failing to include and stage symlinks

repro steps in TypeScript:

  1. create a lambda folder in a project with a handler
  2. ln -s path-to-node_modules path-to-lambda
  3. Reference the asset in your app
const hello = new lambda.Function(this, 'HelloHandler', {
      runtime: lambda.Runtime.NODEJS_10_X, 
      code: lambda.Code.asset('lambda'),
      handler: 'hello.handler' 
    });

Until 1.15.0 This used to yield a staged asset that included node_modules along with the handler on a cdk synthcommand

As of 1.16.0 This fails to resolve with
Error: ENOENT: no such file or directory, symlink '

looking into a fix

@shivlaks shivlaks changed the title Symlink issue after upgrade to 1.16.1 cdk synth fails to resolve symlinks when staging assets as of 1.16.0 Nov 14, 2019
@shivlaks
Copy link
Contributor

seems like the issue was introduced in #4473
@nmussy any ideas?

Reverting it for now - #5022

@shivlaks shivlaks added p1 and removed p0 labels Nov 14, 2019
shivlaks added a commit that referenced this issue Nov 14, 2019
…5022)

This reverts commit b7b4336.

This is being reverted as it introduced a regression in assets that contain symlinks during cdk synth.
Fixes #4978
@jd-carroll
Copy link
Contributor

I know its late on a friday, but any chance there could be a 1.16.3 release cut with this fix?

@jd-carroll
Copy link
Contributor

jd-carroll commented Nov 17, 2019

In case anyone else sees this, just add the following to your package.json

  "resolutions": {
    "@aws-cdk/assets": "1.15.0",
    "@aws-cdk/core": "^1.16.0",
    "@aws-cdk/cx-api": "^1.16.0"
  }

If you have a mono-repo, place it in the root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants