问题
I started deploying my demo Angular 9 application on AWS lambda and provide SSR. In order to achieve this, I used @ng-toolkit/universal and @ng-toolkit/serverless. Deployment happened successfully but demo application is not opening. Upon investigating AWS lambda logs, I found the following exception.
Here is the package.json, where I have added express js in dependencies.
{
"name": "my-appg",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:browser:prod": "ng build --prod",
"build:browser:serverless": "ng build --prod --base-href /production/",
"build:serverless": "npm run build:browser:serverless && npm run build:server:serverless",
"build:prod": "npm run build:browser:prod && npm run build:server:prod",
"server": "node local.js",
"build:prod:deploy": "npm run build:prod && npm run deploy",
"build:serverless:deploy": "npm run build:serverless && npm run deploy",
"deploy": "serverless deploy --aws-profile leaks",
"build:server:prod": "webpack --config webpack.server.config.js --progress --colors",
"build:server:serverless": "webpack --config webpack.server.config.js --progress --colors"
},
"private": true,
"dependencies": {
"@angular-devkit/schematics": "^9.1.3",
"@angular/animations": "~9.0.5",
"@angular/common": "~9.0.5",
"@angular/compiler": "~9.0.5",
"@angular/core": "~9.0.5",
"@angular/forms": "~9.0.5",
"@angular/platform-browser": "~9.0.5",
"@angular/platform-browser-dynamic": "~9.0.5",
"@angular/router": "~9.0.5",
"@ng-toolkit/serverless": "^8.1.0",
"@ng-toolkit/universal": "^1.1.21",
"@schematics/angular": "^9.1.3",
"aws-serverless-express": "^3.3.6",
"cors": "^2.8.5",
"express": "^4.17.1",
"rxjs": "~6.5.4",
"serverless-api-compression": "^1.0.0",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.900.5",
"@angular/cli": "~9.0.5",
"@angular/compiler-cli": "~9.0.5",
"@angular/language-service": "~9.0.5",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~5.18.0",
"typescript": "~3.7.5",
"ts-loader": "^6.2.1",
"webpack-cli": "^3.3.10",
"opencollective": "^1.0.3",
"serverless": "^1.60.0",
"serverless-apigw-binary": "^0.4.4"
}}
and here is server.ts which also seems okay.
// generated by @ng-toolkit/serverless
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import * as express from 'express';
import * as cors from 'cors';
import * as compression from 'compression';
import {join} from 'path';
export const app = express();
app.use(compression());
app.use(cors());
const DIST_FOLDER = join(process.cwd(), 'dist/myPleaks-ng9');
app.get('*.*', express.static(join(DIST_FOLDER), {
maxAge: '1y'
}));
app.get('/*', (req, res) => {
res.sendFile(join(DIST_FOLDER + '/index.html'));
});
Please help me to find out the issue, thanks in advance.
回答1:
I found the solution on github post where "esModuleInterop": true from tsconfig file was required to remove.
来源:https://stackoverflow.com/questions/61436646/aws-lambda-ng-toolkit-failing-for-typeerror-express-is-not-a-function-in-angul