Open dschrempf opened 1 year ago
Facing similar issue on Nixos 23.05 and Nodejs 18.16.3
The CDK package available on nixpkgs is 2.80
Affected CDK CLI Versions on Node 18+ are cli: >=2.80.0 <2.83.1
Fix: Fix is to use cli version 2.87 which isn't available it seems
Or use node js 16
Using nodejs 16 does not resolve the issue on my end. Using npx as mentioned above does work around the issue.
ref: https://github.com/NixOS/nixpkgs/pull/242263 aws-cdk is now at 2.87, and it does not solve the issue.
Facing similar issue
I am experiencing this same issue on macOS.
$ cdk --version
2.99.1 (build b2a895e)
$ nix-info -m
- system: `"x86_64-darwin"`
- host os: `Darwin 22.6.0, macOS 10.16`
- multi-user?: `yes`
- sandbox: `no`
- version: `nix-env (Nix) 2.17.0`
- channels(root): `"home-manager, nixpkgs"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
This is caused by this line in aws-cdk, which I believe is attempting to introspect on its package manifest: https://github.com/aws/aws-cdk/blob/b865320674f97bd7dd7cfcc69235d3521e6aa0d4/packages/aws-cdk/lib/init.ts#L163
When running as packaged in nixpkgs, this manifest variable doesn't contain anything in devDependencies
:
{
name: 'aws-cdk',
description: 'CDK Toolkit, the command line tool for CDK apps',
version: '2.90.0',
// snip
devDependencies: {},
}
But it is defined in the package.json
inside the src
fetched in node-packages.nix
:
{
"name": "aws-cdk",
"description": "CDK Toolkit, the command line tool for CDK apps",
"version": "2.105.0",
// snip
"devDependencies": {
"constructs": "^10.0.0",
// snip
},
}
I'm guessing this might be because aws-cdk
is defined in node-packages.nix
with production = true;
, so devDependencies
get omitted?
aws-cdk = nodeEnv.buildNodePackage {
name = "aws-cdk";
packageName = "aws-cdk";
version = "2.105.0";
# snip
production = true;
};
Attempting to override this with nodePackages.aws-cdk.override { production = false; }
gets me an ENOTCACHED
error which I assume means the dev dependencies aren't captured in the Nix derivation:
npm ERR! code ENOTCACHEDidealTree buildDeps
npm ERR! request to https://registry.npmjs.org/@aws-cdk%2fcdk-build-tools failed: cache mode is 'only-if-cached' but no cached response is available
That's about all the patience I have for digging into this tonight.
Adding my voice as someone who would like to see this fixed. CDK has heavy utilization at workplace.
Somewhat related: https://github.com/svanderburg/node2nix/issues/149.
@schlarpc, reset of devDependencies
seems to happen here: https://github.com/NixOS/nixpkgs/blob/fa15b53dbea5028db38d6e09b4cef6eba42aeebb/pkgs/development/node-packages/node-env.nix#L169.
Here comes another issue: https://github.com/aws/aws-cdk/blob/1fd548588274a83810a55090dcc3a3a152c5116d/packages/aws-cdk/lib/init.ts#L149. Templates for cdk init
are copied from /nix/store with read-only permissions.
I wrote a very dirty workaround for these issues. I return devDependencies
array back into package.json
and cdk gets satisfied it seems.
flake.nix
:
{
description = "AWS CDK";
inputs.nixpkgs.url = github:nixos/nixpkgs;
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.${system}.default = pkgs.mkShell {
packages = [
self.packages.${system}.default
(pkgs.python3.withPackages (ps: [ ps.pip ])) # if you use CDK in python
pkgs.nodejs
];
};
packages.${system}.default = pkgs.nodePackages.aws-cdk.overrideAttrs (_: {
preRebuild = ''
substituteInPlace lib/index.js \
--replace 'await fs27.copy(fromFile,toFile)' 'await fs27.copy(fromFile, toFile); await fs27.chmod(toFile, 0o644);'
tar --to-stdout -xf $src package/package.json \
| ${pkgs.jq}/bin/jq '{"devDependencies"}' > /build/devDependencies.json
'';
postInstall = ''
FIXED_PACKAGE_JSON="$(${pkgs.jq}/bin/jq -s '.[0] * .[1]' package.json /build/devDependencies.json)"
printf "%s\n" "$FIXED_PACKAGE_JSON" > package.json
'';
});
};
}
flake.lock
:
{"nodes": {"nixpkgs": {"locked": {"lastModified": 1708396807, "narHash": "sha256-PRNwdCEknI5tqpdW7HrDzBd7986BDpwaw13C8NLHi9c=", "owner": "nixos", "repo": "nixpkgs", "rev": "a41cc628170e0c3d42f250c7a8be4d0d41a78c82", "type": "github"}, "original": {"owner": "nixos", "repo": "nixpkgs", "type": "github"}}, "root": {"inputs": {"nixpkgs": "nixpkgs"}}}, "root": "root", "version": 7}
I do not understand how to properly patch source code of this TypeScript package. It is already compiled into index.js
when fetched from NPM. However, index.js
contents are altered somehow during the buildNodePackage
and fs29.copy
becomes fs27.copy
.
Workaround if you are in a hurry is to use npx
. This does defeat the purpose of using nix
though
npx aws-cdk init app --language python
Describe the bug
When initializing a project with
aws-cdk
, I get the following error:Expected behavior
The project is correctly initialized.
Additional context
I can initialize the project using
pkgs.nodejs
andnpx aws-cdk init app --language typescript
, which is a bit weird.Notify maintainers
No maintainers are listed.
Metadata
Thanks!
EDIT: When running the failing command with
--verbose
, I get the following stack trace: