By using AWS re:Post, you agree to the Terms of Use
/CDK with typescript - error on cloud9/

CDK with typescript - error on cloud9

0

Hello Everyone,

I tried https://github.com/fortejas/example-serverless-python-api on a cloud9 environment but I got the following error

Commands that I used to setup:

mkdir sample-api
cd sample-api/
cdk init app --language typescript .
cd ~
git clone https://github.com/kasukur/example-serverless-python-api.git
ls -lrt example-serverless-python-api/
cp -rf example-serverless-python-api/lambda-api/ ~/environment/sample-api/.
cd ~/environment/sample-api/
Delete node_modules folder
Delete package-lock.json
npm i @aws-cdk/aws-lambda-python-alpha --force -g

ec2-user:~/environment/sample-api  $ cdk deploy

the error is

ec2-user:~/environment/sample-api  $ cdk synth
npm WARN exec The following package was not found and will be installed: ts-node
/home/ec2-user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:750
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ⨯ Unable to compile TypeScript:
bin/sample-api.ts:4:10 - error TS2305: Module '"../lib/sample-api-stack"' has no exported member 'SampleApiStack'.

4 import { SampleApiStack } from '../lib/sample-api-stack';
~~~~~~~~~~~~~~

at createTSError (/home/ec2-user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:750:12)
at reportTSError (/home/ec2-user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:754:19)
at getOutput (/home/ec2-user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:941:36)
at Object.compile (/home/ec2-user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1243:30)
at Module.m._compile (/home/ec2-user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1370:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (/home/ec2-user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1374:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
diagnosticText: `\x1B[96mbin/sample-api.ts\x1B[0m:\x1B[93m4\x1B[0m:\x1B[93m10\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2305: \x1B[0mModule '"../lib/sample-api-stack"' has no exported member 'SampleApiStack'.\n` +
'\n' +
"\x1B[7m4\x1B[0m import { SampleApiStack } from '../lib/sample-api-stack';\n" +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~~~~~~~\x1B[0m\n',
diagnosticCodes: [ 2305 ]
}
Subprocess exited with error 1

Could someone please help with this

Thank you

1 Answers
2
Accepted Answer

Module '"../lib/sample-api-stack"' has no exported member 'SampleApiStack' points exactly at the root cause. https://github.com/fortejas/example-serverless-python-api/blob/main/lib/sample-api-stack.ts exports ServerlessApiStack, not SampleApiStack!

CDK behavior explanation:

  • cdk.json defines command to compile your CDK application: "app": "npx ts-node --prefer-ts-exts bin/sample-api.ts"
  • bin/sample-api.ts has the following import generated by CDK init command: import { SampleApiStack } from '../lib/sample-api-stack';
  • you replaced the generated file with a custom one, which exports a different class
  • TypeScript fails to compile your code and CDK exists with the error above
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions