Skip to content
This repository has been archived by the owner on Apr 30, 2023. It is now read-only.

Unable to compile TypeScript #30

Open
mattvb91 opened this issue Dec 14, 2020 · 7 comments
Open

Unable to compile TypeScript #30

mattvb91 opened this issue Dec 14, 2020 · 7 comments

Comments

@mattvb91
Copy link

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
Copy link

cynicaljoy commented Dec 15, 2020

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
Copy link
Author

mattvb91 commented Feb 1, 2021

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
Copy link

geNAZt commented Feb 3, 2021

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
Copy link

birtles commented Feb 4, 2021

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

I tried reproducing it in a local Docker container using the commands in #30 (comment) 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
Copy link

birtles commented Feb 4, 2021

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
Copy link

Skona27 commented Feb 9, 2021

@cynicaljoy Any chances of solving this issue?

@GhyslainBruno
Copy link

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

JordWyatt referenced this issue in JordWyatt/bandcamp-release-feed-cdk Oct 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants