AWS re:Postを使用することにより、以下に同意したことになります AWS re:Post 利用規約

relative import resolution error with transpiled TypeScript code in Lambda with container images

0

I'm trying to get started developing a lambda function via typescript.

I've following the instructions here to set up my project: https://docs.aws.amazon.com/lambda/latest/dg/typescript-image.html

The example code given at the link above builds and runs just fine.

But when I modify the code as follows, the build step fails:

  1. I add a file schema.ts in the project's root directory that exports an object like this:
export const ValidRequestObject = {sessionId: 2}
  1. In index.ts I add `import { ValidRequestObject } from './schema'.

Running docker build --platform linux/amd64 -t docker-image:test . now fails. Here's the error:

0.730 ✘ [ERROR] Could not resolve "./schema"
0.730
0.730     index.ts:2:30:
0.730       2 │ import { ValidRequestObject } from './schema';
0.730         ╵                               ~~~~~~~~~~
0.730

To be clear, the above are the ONLY modifications I've made to the example in the documentation linked above.

So I guess the question is: What do I need to do to make relative imports work at the build step?

質問済み 5ヶ月前272ビュー
1回答
0

So the dockerfile suggested by the aws documentation I followed has the line

COPY package.json index.ts ./

I would expect that the ./ part of this would cause every file in the project directory to be copied over to the container.

Apparently not. The problem was fixed by manually adding the file from which index.ts was importing to that line like so:

COPY package.json index.ts schema.ts ./

Although this fixes the problem, I'm still not sure how to cause all the files in the project directory (excepting of course .gitignore) to get copied over to the container before the build step without having to manually write their names into the COPY line as above. If anyone knows, please tell me.

回答済み 5ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ