我试图使用Serverless框架将我的Node.js应用程序部署到Lambda,但是,我的节点代码使用来自tsconfig.json的路径来引用导入,但是Serverless部署过程失败了。如何连接serverless.yml以确认和使用在tsconfig.json中定义的路径?
我已经安装了无服务器插件类型记录,但它似乎无法从tsconfig中识别路径。
serverless.yml
service:
name: app-name
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
plugins:
- serverless-webpack
- serverless-plugin-typescript
...tsconfig.ts
{
"compileOnSave": true,
"compilerOptions": {
"lib": [
"es2017"
],
"baseUrl": "./src",
"declaration": true,
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./dist",
"paths": {
"@config/*": [
"config/*"
],
"@core/*": [
"core/*"
],
"@infra/*": [
"infra/*"
],
"@modules/*": [
"modules/*"
],
"@shared/*": [
"shared/*"
]
},
"preserveConstEnums": true,
"removeComments": true,
"rootDir": "./src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": false,
"target": "es2017",
"typeRoots": [
"node_modules/@types"
],
"types": [
"node"
]
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules/**/*",
".serverless/**/*",
".webpack/**/*",
"_warmup/**/*",
".vscode/**/*"
]
}发布于 2020-05-21 15:33:29
我找到了答案。结果发现,您需要安装tsconfig-路径-webpack-插件。然后在webpack.config.js中添加以下内容:
npm install --save-dev tsconfig-paths-webpack-plugin在webpack.config.js内部:
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
...
resolve: {
plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.json" })]
},
...
};注意:一定要使用解决部分中的插件。有一个插件是根,但是TsconfigPathsPlugin只在解析/插件中工作。
如果你经历了同样的问题,我希望这对你有帮助。
https://stackoverflow.com/questions/61936928
复制相似问题