Ao usar o AWS re:Post, você concorda com os AWS re:Post Termos de uso

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?

feita há 5 meses272 visualizações
1 Resposta
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.

respondido há 5 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas