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

[Bug]: #151

Open
1 task
denniske opened this issue Nov 20, 2024 · 8 comments
Open
1 task

[Bug]: #151

denniske opened this issue Nov 20, 2024 · 8 comments
Labels
@astro-aws/constructs bug Something isn't working

Comments

@denniske
Copy link

denniske commented Nov 20, 2024

💻

  • 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

@denniske denniske added bug Something isn't working needs triage labels Nov 20, 2024
@denniske
Copy link
Author

As a workaround I just copied the costructs folder into my app and then everything worked.

@lukeshay
Copy link
Owner

storycdk-stack.ts

Can you add the contents of storycdk-stack.ts?

@denniske
Copy link
Author

Here is the repo: https://github.com/denniske/storycdk

@lukeshay
Copy link
Owner

lukeshay commented Nov 26, 2024

Here is the repo: https://github.com/denniske/storycdk

We only support ESM. Could you do the following:

  1. Add "type": "module" to package.json
  2. Use ts-node-esm in app.json
  3. Set module to NodeNext in tsconfig.json

I would also recommend using tsx instead of ts-node

@denniske
Copy link
Author

I applied 1. and 2. but I don't have a file called app.json

@denniske
Copy link
Author

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.

@lukeshay
Copy link
Owner

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

@denniske
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@astro-aws/constructs bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants