I’m working with aws amplify, and uses lambda layers and also typescript. Because my project is big, I simplified my folder structure to explain my problem
On the root level i have the amplify folder, which contains an inside a folder for each lambda function and each lambda layers.
Also on the root level, I introduced an "amplifyTypescript" folder, which contains also folders for each lambda and each lamda layer for the typescript sources.
The tsconfig.json looks like this.
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "../../amplify/backend/function/lambdaFunction1",
"rootDir": ".",
"sourceMap": true,
"strict": false,
"experimentalDecorators": true,
"baseUrl": ".",
"resolveJsonModule": true,
"paths": {
"/opt/lambdaLayer/database/index": ["../lambdaLayer/database/index"]
}
},
"exclude": [
"../lambdaLayer/",
"lambdaLayer/database/index.ts",
"**/lambdaLayer**",
"../lambdaLayer/database/index",
"/opt/lambdaLayer/database/index"
]
}
In lambdaFunction1 i have the following import statement. import { fConnect } from '/opt/lambdaLayer/database/index';
The Problem which occurred at first was, that the path /opt/... obviosly didn't exist on my laptop. Therefore i introduced the mapping of paths in the tsconfig (see above).
Then i got the error that ../lambdaLayer/database/index is outside of the "rootDir" of lambdaFunction1. This is correct, but it's a lambdaLayer. At the End I want to ignore this at transpile process....
Therefore i ignored this error using: // @ts-ignore
Now everything works fine during development. The IDE considers the path-mapping in tsconfig, and i can develop my code. But when i run "tsc" in lambdaFunction1, the system tries to transpile the lambdaLayer also, and this throws several issues regarding problems with relatives paths.
As you can see, i tried it with several excludes in tsconfig, but as far as i learned, excludes are ignored if there is an import statement.
Currently i haven't a clue, how to handle this situation. Typescript should just "believe" me, that at the end the file will be accessable via: /opt/lambdaLayer/database/index
Can someone help me?
Kind Regards Stefan
