Serverless framework Web包:configuration.entry应为非空对象
Serverless framework Web包:configuration.entry应为非空对象,serverless-framework,serverless-webpack-plugin,Serverless Framework,Serverless Webpack Plugin,serverless deploy正在使用最新的网页版本引发此错误 Serverless: Bundling with Webpack... Webpack Options Validation Error ----------------------- WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration obje
serverless deploy
正在使用最新的网页版本引发此错误
Serverless: Bundling with Webpack...
Webpack Options Validation Error -----------------------
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.entry should be a non-empty object.
webpack.config.js
const path = require('path');
const slsw = require('serverless-webpack');
// var nodeExternals = require('webpack-node-externals')
module.exports = {
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
// externals: [nodeExternals()],
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: 'ts-loader' },
],
},
};
package.json
"serverless": "^1.72.0",
"serverless-aws-documentation": "^1.1.0",
"serverless-dynamodb-local": "^0.2.39",
"serverless-iam-roles-per-function": "^2.0.2",
"serverless-offline": "^6.4.0",
"serverless-reqvalidator-plugin": "^1.0.3",
"serverless-s3-local": "^0.6.2",
"serverless-webpack": "^5.3.2",
"ts-loader": "^7.0.5",
"typescript": "^3.9.5",
"webpack": "^4.43.0"
这里有一些相关的东西:
yml是非常标准的,它使用的是较旧的网页包版本。
这里不是网页专家,非常感谢您的帮助 解决方案是从头开始重新创建项目并重新安装包:
sls创建--模板aws节点JS类型脚本--路径项目名称
在本例中,webpack.config.json生成如下所示:
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
context: __dirname,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
devtool: slsw.lib.webpack.isLocal ? 'cheap-module-eval-source-map' : 'source-map',
resolve: {
extensions: ['.mjs', '.json', '.ts'],
symlinks: false,
cacheWithContext: false,
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
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
// }
// })
],
};
和package.json:
"@types/aws-lambda": "^8.10.17",
"@types/node": "^10.12.18",
"fork-ts-checker-webpack-plugin": "^3.0.1",
"serverless": "^1.73.1",
"serverless-aws-documentation": "^1.1.0",
"serverless-dynamodb-local": "^0.2.39",
"serverless-iam-roles-per-function": "^2.0.2",
"serverless-offline": "^6.4.0",
"serverless-reqvalidator-plugin": "^1.0.3",
"serverless-s3-local": "^0.6.2",
"serverless-webpack": "^5.2.0",
"ts-loader": "^5.3.3",
"typescript": "^3.2.4",
"webpack": "^4.29.0",
"webpack-node-externals": "^1.7.2"
离线部署和云部署都可以正常工作。解决方案是从头开始重新创建项目并重新安装包:
sls创建--模板aws节点JS类型脚本--路径项目名称
在本例中,webpack.config.json生成如下所示:
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
context: __dirname,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
devtool: slsw.lib.webpack.isLocal ? 'cheap-module-eval-source-map' : 'source-map',
resolve: {
extensions: ['.mjs', '.json', '.ts'],
symlinks: false,
cacheWithContext: false,
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
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
// }
// })
],
};
和package.json:
"@types/aws-lambda": "^8.10.17",
"@types/node": "^10.12.18",
"fork-ts-checker-webpack-plugin": "^3.0.1",
"serverless": "^1.73.1",
"serverless-aws-documentation": "^1.1.0",
"serverless-dynamodb-local": "^0.2.39",
"serverless-iam-roles-per-function": "^2.0.2",
"serverless-offline": "^6.4.0",
"serverless-reqvalidator-plugin": "^1.0.3",
"serverless-s3-local": "^0.6.2",
"serverless-webpack": "^5.2.0",
"ts-loader": "^5.3.3",
"typescript": "^3.2.4",
"webpack": "^4.29.0",
"webpack-node-externals": "^1.7.2"
脱机部署和云部署都可以正常工作。对于我来说,如果没有任何函数或资源添加到堆栈文件,就会发生这种情况。对于我来说,如果没有任何函数或资源添加到堆栈文件,就会发生这种情况。