Я пытаюсь aws -сам с помощью typeorm. Как только я запускаю свое приложение (sam local start-api
) и пытаюсь поразить API. Это дает мне следующую ошибку:
Cannot find module 'typeorm'
Ниже приведен полный стек ошибок:
START RequestId: b4a62bc1-323c-17e0-ca57-755904831b77 Version: $LATEST
Unable to import module 'handler': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/database.js:3:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
END RequestId: b4a62bc1-323c-17e0-ca57-755904831b77
REPORT RequestId: b4a62bc1-323c-17e0-ca57-755904831b77 Init Duration: 200.85 ms Duration: 10.13 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 39 MB
Invalid API Gateway Response Keys: {'errorMessage', 'stackTrace', 'errorType'} in {'errorType': 'Error', 'errorMessage': "Cannot find module 'typeorm'", 'stackTrace': ['Function.Module._load (module.js:474:25)', 'Module.require (module.js:596:17)', 'require (internal/module.js:11:18)', 'Object.<anonymous> (/var/task/database.js:3:19)', 'Module._compile (module.js:652:30)', 'Object.Module._extensions..js (module.js:663:10)', 'Module.load (module.js:565:32)', 'tryModuleLoad (module.js:505:12)', 'Function.Module._load (module.js:497:3)']}
Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object). Response received: {"errorType":"Error","errorMessage":"Cannot find module 'typeorm'","stackTrace":["Function.Module._load (module.js:474:25)","Module.require (module.js:596:17)","require (internal/module.js:11:18)","Object.\u003canonymous\u003e (/var/task/database.js:3:19)","Module._compile (module.js:652:30)","Object.Module._extensions..js (module.js:663:10)","Module.load (module.js:565:32)","tryModuleLoad (module.js:505:12)","Function.Module._load (module.js:497:3)"]}
2020-01-26 10:39:26 127.0.0.1 - - [26/Jan/2020 10:39:26] "GET /programs HTTP/1.1" 502 -
2020-01-26 10:39:27 127.0.0.1 - - [26/Jan/2020 10:39:27] "GET /favicon.ico HTTP/1.1" 403 -
Когда я пытаюсь без typeorm, он работает нормально.
Фрагмент кода, где я использую typeorm:
import { Connection } from "typeorm";
import { Database } from "./../database";
export default class TestService {
constructor() {}
public async getTest(): Promise<any> {
const database = new Database();
// code works when i remove the below line
let dbConn: Connection = await database.getConnection();
return {
name: "testing"
};
}
}
tsconfig. json:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["es7", "esnext.asynciterable"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"baseUrl": ".",
"rootDir": "src/",
"outDir": "dist/src",
"sourceMap": true,
"paths": {
"*": ["node_modules/*", "src/types/*"]
},
"allowJs": true
},
"include": ["src/**/*"],
"exclude": ["**/*.spec.*"]
}
фрагмент пакета. json:
"dependencies": {
"lodash": "^4.17.15",
"typedi": "^0.8.0",
"pg": "^7.17.0",
"dotenv": "^8.2.0",
"typeorm": "^0.2.22",
"typeorm-typedi-extensions": "^0.2.3"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.3",
"@types/chai": "^4.1.3",
"@types/jest": "^23.1.4",
"@types/node": "^10.0.4",
"@types/node-fetch": "^2.5.4",
"concurrently": "^5.0.2",
"nodemon": "^2.0.2",
"aws-sdk": "^2.234.1",
"jest": "^23.3.0",
"ts-jest": "^23.0.0",
"ts-loader": "^4.2.0",
"ts-node": "^6.0.3",
"tslint": "^5.8.0",
"tslint-config-prettier": "^1.12.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.8.3",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.7.0",
"webpack-cli": "^3.1.1",
"yaml-cfn": "^0.2.0"
},