Using webpack we get warnings in typescript file
First of all, thank you for the library.
However, seeing warnings like this when compiling with webpack. Any ideas on how to fix?
WARNING in ./node_modules/aws-lambda-router/lib/proxyIntegration.d.ts 3:8
Module parse failed: Unexpected token (3:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import { APIGatewayEventRequestContext, APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
| import { ProcessMethod } from './EventProcessor';
> declare type ProxyIntegrationParams = {
| paths?: {
| [paramId: string]: string;
@ ./node_modules/aws-lambda-router/lib sync ^\.\/.*$ ./proxyIntegration.d.ts
@ ./node_modules/aws-lambda-router/index.js
@ ./src/lambdas/es_manager.ts
Webpack config is like this:
const path = require('path');
const fs = require('fs');
const nodeBuiltins = require('builtin-modules');
const lambdaDir = path.join('.', 'src', 'lambdas');
const lambdaNames = fs.readdirSync(path.join(__dirname, lambdaDir));
const DIST_DIR = path.join(__dirname, 'dist');
const entry = lambdaNames
.reduce((entryMap, lambdaName) => {
entryMap[lambdaName.replace('.ts', '')] = path.join(__dirname, lambdaDir, `${lambdaName}`);
return entryMap;
}, {});
const externals = ['aws-sdk']
.concat(nodeBuiltins)
.reduce((externalsMap, moduleName) => {
externalsMap[moduleName] = moduleName;
return externalsMap;
}, {});
module.exports = {
entry: entry,
externals: externals,
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
},
output: {
libraryTarget: 'commonjs',
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
optimization:{
minimize: false, // <---- disables uglify.
// minimizer: [new UglifyJsPlugin()] if you want to customize it.
},
target: 'node',
mode: 'production'
};
package.json is this
{
"name": "test",
"version": "1.0.0",
"description": "test-test",
"main": "index.js",
"scripts": {
"compile": "rm -rf ./dist && tsc",
"package": "rm -rf ./dist && webpack",
"build": "npm run package && rm -f ./main.zip && cd ./dist && zip -r ../main .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-lambda-router": "^0.8.3"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.57",
"@types/node": "^14.0.14",
"aws-sdk": "^2.705.0",
"builtin-modules": "^3.1.0",
"ts-loader": "^7.0.5",
"typescript": "^3.9.5",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
}
}
Version 0.6.2 doesn't have this problem.
Hi, I also have this problem. I solved it by ignoring .d.ts files in webpack.config.js for ts-loader, but I think it is related to the way the .d.ts files are shipped with aws-lambda-router. Maybe because your index.d.ts does not export all types that are needed externally? Could be that by having to import .d.ts files lower in the package (e.g. proxyintegration.d.ts) this triggers this error? unfortunately sqs, s3 and sns export the same name 'process' so this might not work in the current state. Any more thoughts on this? Happy to provide an example if needed.