Open yankeeinlondon opened 6 years ago
This is the specific line in serverless-webpack which it is failing on:
config.output.path = path.join(config.output.path, compileName);
Based on this error I thought maybe I needed to explicitly state an output directory so I included the following:
output: {
libraryTarget: "commonjs",
path: path.resolve(__dirname, ".webpack"),
filename: "[name].js"
}
Which is again straight out of the docs. As you may be able to tell, I'm no expert on webpack but I'm trying to follow the docs as closely as possible.
Finally as a desperate step, I introduced ts-loader
as the source files are actually TS. That changed the webpack.config.js
to:
const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
module.exports = async () => {
return {
entry: slsw.lib.entries,
resolve: {
extensions: [".js", ".json", ".ts", ".tsx"]
},
output: {
libraryTarget: "commonjs",
path: path.resolve(__dirname, ".webpack"),
filename: "[name].js"
},
target: "node",
externals: [nodeExternals()],
mode: slsw.lib.webpack.isLocal ? "development" : "production",
module: {
rules: [
{
test: /\.ts(x?)$/,
use: [
{
loader: "ts-loader"
}
]
}
]
}
};
};
Still same error.
Hi @ksnyde , can you check if you specified the handler
property of your functions correctly?
If they are located in a subfolder, you should specify them as subdir/myhandler.handlerfunc
without any leading ./
.
Hi @ksnyde, is this still an issue for you? I have a similar setup (TypeScript + Webpack) and I don't seem to have the same issue...
I am getting this same issue with TS, Node, and Serverless Webpack. Not only is config.output.path
undefined but the whole config
is an empty object {}. Something with the webpackConfig
path in the serverless.yml is changing when I add some TS plugin (I've tested with both serverless-plugin-typescript
and @kingdarboja/serverless-plugin-typescript
). It says it cannot find webpackConfig path looking in the .build
folder when TS plugin is enabled, If I change the relative path to outside the .build
folder I will get this path undefined
error. If I remove TS plugin and use the normal webpack path I will also get an empty config with the path undefined
error. I'm using TsconfigPathsPlugin
as well as awesome-typescript-loader
in my webpack config I don't know if that is causing the issue. I've posted more of my details in the serverless forums here: https://forum.serverless.com/t/serverless-plugins-just-keep-giving-new-errors/14168
Update: Finally got passed this error, basically my config in webpack was an async function that returned a config object. I changed it into just a regular config object and it started parsing correctly!
resolved by changing from module.exports
to exports
I have several handler functions in the
/lib/handlers
directory and myserverless.yml
file correctly points to them. After adding serverless-webpack I am able to do a full deploy or a function deploy. In both cases I get the error:When turning on debugging I can see the following steps are completed before the error is throw:
Further, the
webpack.config.js
file in the packages root folder (along withserverless.yml
) is:This is pretty much boilerplate from the docs. Further my config in the
serverless.yml
is:Note I have alternated npm and yarn as the packager but both produce the same results. I am using the following versions:
sls:
1.30.0
node:8.11.3
os: macOS 10.13.6 cloud: AWS serverless-webpack:5.2.0
webpack:4.16.5
webpack-node-externals:1.7.2
Finally, here is the stack-trace of the error: