我无法用无服务器包插件生成包。
tsconfig.json
{
"compilerOptions": {
"lib": ["es2017"],
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "es2017",
"outDir": "dist",
"declaration": true,
"sourceMap": true,
"baseUrl": ".",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowJs": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["./dist/**/*", "./node_modules/**/*"]
}serverless.yml
service: serverless-boilerplate
custom:
# Our stage is based on what is passed in when running serverless
# commands. Or falls back to what we have set in the provider section.
stage: ${opt:stage, 'offline'}
region: ${opt:region, 'us-east-1'}
bundle:
linting: false
serverless-offline:
httpPort: 4000
noPrependStageInUrl: true
provider:
name: aws
runtime: nodejs14.x
memorySize: 512
timeout: 10
logRetentionInDays: 90
lambdaHashingVersion: 20201221 # https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
logs:
httpApi: true
httpApi:
# metrics: true # Enable if you need
cors: true
functions:
app:
handler: src/handler.handler
# reservedConcurrency: 100
events:
- httpApi:
path: '/{proxy+}'
method: '*'
package:
individually: true
plugins:
- serverless-dotenv-plugin
- serverless-bundle
- serverless-offline以下是运行.serverless/app.zip后的sls package文件

正如您所看到的,没有node_modules文件夹。
如果我用sls offline start --stage offline启动这个应用程序

它看起来像是试图在node_modules中自己的包文件夹中读取目录(资源)的依赖关系之一:

但是由于serverless-bundle将所有内容合并到handler.js中,所以没有node_modules文件夹和依赖文件夹,所以readdir()失败了。
我做错什么了?
发布于 2021-11-13 09:27:07
看起来,将externals: all添加到serverless.yml中的custom.bundle解决了这个问题。
https://stackoverflow.com/questions/69952799
复制相似问题