我正在做一个基于云的项目,它是用typescript构建的。来部署我们使用的服务
build : serverless webpack --stage=dev
deploy: serverless deploy --stage=dev当在serverless.yml中定义的函数名大于10或11时,我将面临以下问题。
func-abc:
handler: src/api/get-user-details
events:
- http:
authorizer: ${file(authorizer.yml)}
path: /user/{user-id}/
method: GET
parameters:
paths:
user-id: true
cors: true
webpack-config.js
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
context: __dirname,
mode: 'production',
entry: slsw.lib.entries,
devtool: 'source-map',
resolve: {
extensions: ['.mjs', '.json', '.ts'],
symlinks: false,
cacheWithContext: false,
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
optimization: {
minimize: true,
},
externals: [nodeExternals()],
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.(tsx?)$/,
loader: 'ts-loader',
exclude: [
[
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '.serverless'),
path.resolve(__dirname, '.webpack'),
],
],
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin({
eslint: true,
eslintOptions: {
cache: true
}
}),
new CopyWebpackPlugin([
{from: 'config/*.json', to: ''},
{from: 'config/*.pem', to: ''},
])
],
};(node:9972) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)在此警告之后,代码不会部署到AWS。
如何解决这个问题。
提前谢谢。
发布于 2021-02-17 00:32:13
它适用于我的以下webpack.config.js:
const serverlessWebpack = require('serverless-webpack');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const TerserPlugin = require('terser-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
devtool: 'inline-cheap-module-source-map',
entry: serverlessWebpack.lib.entries,
mode: 'production',
module: {
rules: [{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true
}
}
],
},
node: false,
externals: [nodeExternals()],
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true,
}
}
)],
},
resolve: {
extensions: ['.mjs', '.ts', '.js']
},
plugins: [
new ForkTsCheckerWebpackPlugin()
],
target: 'node',
};最近,我正在解决类似的问题。有关详细指南( serverless+webpack),请参阅此处
https://stackoverflow.com/questions/65750994
复制相似问题