使用TypeScript的CDK - 在Cloud9上出现错误。

0

【以下的问题经过翻译处理】 我在Cloud9环境中尝试使用 https://github.com/fortejas/example-serverless-python-api,但是出现了以下错误。

我使用的设置命令如下:

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

错误为


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

有人能帮忙看看这是怎么回事吗? 谢谢!

1 Antwort
0

【以下的回答经过翻译处理】 模块“' ../lib/sample-api-stack '”没有导出成员' SampleApiStack'”,这是出现问题的根本原因。 https://github.com/fortejas/example-serverless-python-api/blob/main/lib/sample-api-stack.ts 导出ServerlessApiStack而不是SampleApiStack

CDK行为解释:

  • cdk.json 定义了编译CDK应用程序的命令:"app":"npx ts-node --prefer-ts-exts bin/sample-api.ts"
  • bin/sample-api.ts 由CDK init命令生成以下导入:import { SampleApiStack } from '../lib/sample-api-stack';
  • 你用自定义文件替换了生成的文件,该文件导出了不同的类
  • TypeScript在编译你的代码时出现错误,CDK出现上述错误。
profile picture
EXPERTE
beantwortet vor 5 Monaten

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