Hi,
Using ts-node I'm trying to use Typescript directly inside lambda function on AWS, to do this I'm using this sample code:
require('ts-node/register');
console.log('Register!');
const { main } = require('./src/test.ts');
exports.handler = async function handler() {
console.log('Starting...');
await main();
console.log('Done!');
};
The problem is that in my lambda the node_modules directory is placed in a layer /opt/nodejs/node_modules
So what happens is that ts-node doesn't find libraries on the imported sources giving errors such:
src/test.ts(2,21): error TS2307: Cannot find module '@aws-sdk/client-s3' or its corresponding type declarations.
I'm trying to override the configuration of ts-node using this code, but still no luck.
var tsNode = require('ts-node');
var service = tsNode.register({
lazy: true,
files: false,
compilerOptions: {
"target": "ES2019",
"module": "commonjs",
"lib": [
"DOM",
"ES6",
"ES2019",
"ES2020"
],
"declaration": true,
"strict": false,
"noImplicitAny": false,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"inlineSourceMap": true,
"inlineSources": true,
"strictPropertyInitialization": true,
"baseUrl": "/opt/nodejs/",
"types": [
"node",
"aws-lambda"
],
"typeRoots": [
"node_modules",
"node_modules/@types",
]
}
});
Thanks you in advance,
Regards
Hi,
Using
ts-nodeI'm trying to use Typescript directly inside lambda function on AWS, to do this I'm using this sample code:The problem is that in my lambda the node_modules directory is placed in a layer
/opt/nodejs/node_modulesSo what happens is that ts-node doesn't find libraries on the imported sources giving errors such:
I'm trying to override the configuration of ts-node using this code, but still no luck.
Thanks you in advance,
Regards