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 Antwort
3
Akzeptierte Antwort

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
AWS
beantwortet vor 2 Jahren
  • Thank you so much. I understand now After deploying the application, I was getting the following error when i access

    curl -d POST https://0am0475yv4.execute-api.ap-southeast-2.amazonaws.com/prod/update

    [ERROR] Runtime.ImportModuleError: Unable to import module 'server': No module named 'server'
    Traceback (most recent call last):
    
  • The same thing happened to me, I had a custom class name.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen