aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.49k stars 3.84k forks source link

cdk init failed with node 22.5.0 #30889

Closed chenrui333 closed 1 month ago

chenrui333 commented 1 month ago

Describe the bug

failed to run cdk init with nodejs 22.5.0 environment

==> /opt/homebrew/Cellar/aws-cdk/2.149.0/bin/cdk list
node:internal/modules/cjs/loader:1222
  throw err;
  ^

Error: Cannot find module 'constructs'
Require stack:
- /private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/lib/stack.js
- /private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/lib/index.js
- /private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/index.js
- /private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/index.js
- /private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/bin/testapp.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1219:15)
    at Module._load (node:internal/modules/cjs/loader:1045:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
    at Module.require (node:internal/modules/cjs/loader:1304:12)
    at require (node:internal/modules/helpers:123:16)
    at constructs_1 (/private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/lib/stack.js:1:464)
    at Object.<anonymous> (/private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/lib/stack.js:1:2544)
    at Module._compile (node:internal/modules/cjs/loader:1504:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1588:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/lib/stack.js',
    '/private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/lib/index.js',
    '/private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/core/index.js',
    '/private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/node_modules/aws-cdk-lib/index.js',
    '/private/tmp/aws-cdk-test-20240718-31116-9aq66x/testapp/bin/testapp.js'
  ]
}

Node.js v22.5.0

Expected Behavior

should pass

Current Behavior

failed

Reproduction Steps

Possible Solution

No response

Additional Information/Context

relates to https://github.com/Homebrew/homebrew-core/pull/177645 full build log, https://github.com/Homebrew/homebrew-core/actions/runs/9980021240/job/27594462685?pr=177645

CDK CLI Version

2.149.0

Framework Version

No response

Node.js Version

22.5.0

OS

macOS/Linux

Language

TypeScript

Language Version

No response

Other information

No response

ashishdhingra commented 1 month ago

@chenrui333 Good morning. Thanks for opening the issue. Somehow the issue is not reproducible on fresh Amazon Linux 2023 instance using Nodejs 22.5.0 and CDK version 2.149.0 (build c8e5924). Running cdk init, after installing all the pre-requisites (I installed Nodejs using nvm per instructions at https://nodejs.org/en/download/package-manager/current and also installed typescript per https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html), gives the below output:

# Welcome to your CDK TypeScript project

This is a blank project for CDK development with TypeScript.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

## Useful commands

* `npm run build`   compile typescript to js
* `npm run watch`   watch for changes and compile
* `npm run test`    perform the jest unit tests
* `npx cdk deploy`  deploy this stack to your default AWS account/region
* `npx cdk diff`    compare deployed stack with current state
* `npx cdk synth`   emits the synthesized CloudFormation template

Initializing a new git repository...
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>
Executing npm install...
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error   <https://github.com/npm/cli/issues>
npm error A complete log of this run can be found in: /home/ec2-user/.npm/_logs/2024-07-18T17_31_27_666Z-debug-0.log
✅ All done!

I noticed that you mentioned that this issue could be due to version of Homebrew. Could you please share what is the version of Homebrew installed on your system by running brew --version?

Thanks, Ashish

avoidik commented 1 month ago

nodejs has reported a problem in nodejs 22.5.0 with advice to rollback to 22.4.1, link

chenrui333 commented 1 month ago

probably this issue, https://github.com/nodejs/node/pull/53934

homebrew has shipped the node 22.5.1 (it works fine with that release), closing this report.

github-actions[bot] commented 1 month ago

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

aws-cdk-automation commented 1 month ago

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.