youyo / aws-cdk-github-actions

MIT License
205 stars 101 forks source link

Unable to compile TypeScript #30

Open mattvb91 opened 3 years ago

mattvb91 commented 3 years ago

I have all the dependancies installed & already built tsc our code but still getting the following error:

⨯ Unable to compile TypeScript:
bin/stack.ts(2,22): error TS2307: Cannot find module '@aws-cdk/core' or its corresponding type declarations.

@aws-cdk/core is defined in package.json so not really sure why it can't find it

cynicaljoy commented 3 years ago

Are you able to recreate the error in a container locally?

docker run --rm -it --entrypoint /bin/sh -v $PWD:/app -w /app alpine:3
apk --update --no-cache add nodejs nodejs-npm python3 py3-pip jq curl bash git docker
npm install typescript
npm install -g aws-cdk
cdk list

If you want to run cdk diff you'll need to add your credentials:

export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
cdk diff

Asking because I'm using this action with a cdk TypeScript project without any issues. I'm taking a blind guess (being that I cannot see the package.json) that one/more of your dependencies are installed globally or defined incorrectly which is causing this.

mattvb91 commented 3 years ago

Hi @cynicaljoy just ran your first example through container locally in a new cdk project that was initialized with the following command:

 cdk init sample-app --language typescript

and still getting the same error as above with a default project.

cdk version: 1.74.0 (build e86602f)
geNAZt commented 3 years ago

I'm having the same issue in this run: https://github.com/gomint/aws/runs/1823323408?check_suite_focus=true. The package.json has been generated with cdk init like mentioned above.

When i manually install with the docker example you gave it works. At least cdk synth generates a cloudformation stack

birtles commented 3 years ago

I also came across using a project setup with cdk init.

I tried reproducing it in a local Docker container using the commands in https://github.com/youyo/aws-cdk-github-actions/issues/30#issuecomment-745641236 and succeeded. Curiously when I looked in to node_modules/@aws-cdk there was no core there.

I tried to debug what was going on by running through the steps again, but the second time around Docker would just fail to connect (I blame WSL).

From what I can tell, it seems like cdk init makes @aws-cdk/core a regular package dependency, rather than a dev dependency. If I move it to devDependencies it works.

The same appears to be true for the source-map-support module. It would fail to find it until I move it to a dev dependency. I don't know which command is causing these regular dependencies to be nuked but something appears to be doing so.

For what it's worth, I am using yarn so it may be a result of npm 6 not recognizing yarn.lock, and somehow clobbering things when it runs npm install typescript or npm install -g aws-cdk? That said, I couldn't reproduce that behavior locally.

That said, having fixed the above issues I now run into:

esbuild cannot run locally. Switching to Docker bundling.
 > error: Could not read from file: /asset-input/...
birtles commented 3 years ago

For what it's worth, I just ended up forking this and switching to using yarn everywhere. I also made it install esbuild locally in order to avoid the read errors I received. (And I dropped the Python-related parts since I have no need for it.)

Skona27 commented 3 years ago

@cynicaljoy Any chances of solving this issue?

GhyslainBruno commented 3 years ago

Hi all, just to add some info about it.

@birtles I can confirm that moving every dependencies to devDependencies did the trick for me (fixed my Unable to compile TypeScript error, it didn't find @aws-cdk/aws-rds, which was declared in my dependencies).

For the record, I'm using yarn (I knew that using yarn instead of npm would somewhere be a pain in the *ss, since it's not even mentioned in the AWS documentation...).

Anyway, if this can help someone