[Bug]: Update repo and docs to use tsx instead of ts-node
💻
- [ ] Would you like to work on a fix?
Input code
This is a repo that I created following the astro aws tutorial: https://www.astro-aws.org/guides/01-getting-started/
Current and expected behavior
When running cdk deploy I get an error message:
➜ storycdk cdk deploy
/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/index.js:851
return old(m, filename);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/dennis/Projects/storycdk/node_modules/@astro-aws/constructs/dist/index.js from /Users/dennis/Projects/storycdk/lib/storycdk-stack.ts not supported.
Instead change the require of index.js in /Users/dennis/Projects/storycdk/lib/storycdk-stack.ts to a dynamic import() which is available in all CommonJS modules.
at require.extensions.<computed> [as .js] (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/index.js:851:20)
at Object.<anonymous> (/Users/dennis/Projects/storycdk/lib/storycdk-stack.ts:5:22)
at m._compile (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/index.js:857:29)
at require.extensions.<computed> [as .ts] (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/index.js:859:16)
at Object.<anonymous> (/Users/dennis/Projects/storycdk/bin/storycdk.ts:5:26)
at m._compile (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/index.js:857:29)
at require.extensions.<computed> [as .ts] (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/index.js:859:16)
at phase4 (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/bin.js:466:20)
at bootstrap (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/bin.js:54:12)
at main (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/bin.js:33:12)
at Object.<anonymous> (/Users/dennis/Projects/storycdk/node_modules/ts-node/dist/bin.js:579:5) {
code: 'ERR_REQUIRE_ESM'
}
Subprocess exited with error 1
Environment
node v18.20.4 yarn 1.22.22 cdk 2.168.0 (build f4a02ab)
{
"name": "storycdk",
"version": "0.1.0",
"bin": {
"storycdk": "bin/storycdk.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "22.7.9",
"aws-cdk": "2.168.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "~5.6.3"
},
"dependencies": {
"@astro-aws/constructs": "^0.7.0",
"aws-cdk-lib": "2.168.0",
"constructs": "^10.0.0"
}
}
Possible solution
No response
Additional context
No response
As a workaround I just copied the costructs folder into my app and then everything worked.
storycdk-stack.ts
Can you add the contents of storycdk-stack.ts?
Here is the repo: https://github.com/denniske/storycdk
Here is the repo: https://github.com/denniske/storycdk
We only support ESM. Could you do the following:
- Add
"type": "module"topackage.json - Use
ts-node-esminapp.json - Set
moduletoNodeNextintsconfig.json
I would also recommend using tsx instead of ts-node
I applied 1. and 2. but I don't have a file called app.json
yarn add ts-node-esm gives me the following error:
➜ storycdk yarn add ts-node-esm
yarn add v1.22.22
warning package.json: No license field
warning [email protected]: No license field
[1/4] 🔍 Resolving packages...
warning ts-node-esm > aria-build > [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
warning ts-node-esm > aria-build > @rollup/plugin-commonjs > [email protected]: Glob versions prior to v9 are no longer supported
warning ts-node-esm > aria-build > magic-string > [email protected]: Please use @jridgewell/sourcemap-codec instead
warning ts-node-esm > aria-build > @rollup/plugin-multi-entry > matched > [email protected]: Glob versions prior to v9 are no longer supported
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
warning "ts-node-esm > [email protected]" has unmet peer dependency "@swc/core@>=^1.2.5".
warning "ts-node-esm > [email protected]" has incorrect peer dependency "aria-fs@>=^0.4.5".
warning "ts-node-esm > [email protected]" has incorrect peer dependency "typescript@<=^3.9.5".
warning "ts-node-esm > aria-build > [email protected]" has incorrect peer dependency "typescript@^4.0.5".
warning " > [email protected]" has incorrect peer dependency "typescript@>=^3.9.3".
[4/4] 🔨 Building fresh packages...
error /Users/dennis/Projects/storycdk/node_modules/esbuild: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: /Users/dennis/Projects/storycdk/node_modules/esbuild
Output:
error: Unsupported platform: darwin arm64 LE
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
I applied 1. and 2. but I don't have a file called app.json
I meant to say cdk.json. ts-node-esm comes with ts-node
That seems to work although there is another error. I am not actively working on the project anymore, so I have deleted the ssm environment already.
➜ storycdk cdk deploy
node:internal/process/esm_loader:40
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/esm' is not defined by "exports" in /Users/dennis/Projects/storycdk/node_modules/ts-node/package.json
at new NodeError (node:internal/errors:405:5)
at exportsNotFound (node:internal/modules/esm/resolve:366:10)
at packageExportsResolve (node:internal/modules/esm/resolve:713:9)
at resolveExports (node:internal/modules/cjs/loader:590:36)
at Module._findPath (node:internal/modules/cjs/loader:664:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1126:27)
at Module._load (node:internal/modules/cjs/loader:981:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:177:18)
at file:///Users/dennis/Projects/storycdk/node_modules/ts-node-esm/bin/esm.mjs:13:13 {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v18.20.4
✨ Synthesis time: 0.73s
current credentials could not be used to assume 'arn:aws:iam::...:role/cdk-...-deploy-role-982063057166-us-east-1', but are for the right account. Proceeding anyway.
****************************************************
*** Newer version of CDK is available [2.171.1] ***
*** Upgrade recommended (npm install -g aws-cdk) ***
****************************************************
StorycdkStack: SSM parameter /cdk-bootstrap/hnb659fds/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)
using tsx instead of ts-node fixed the error coming from cdk.json for me.
People generally recommend using tsx instead of ts-node nowadays so that may be a good tweak to check in.