-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loading native library failing with "Can't resolve" error #386
Comments
Hi @haridas . You use
which bundles (i.e. integrates) the module into your code. I believe that is the reason for the actual error during building. Can you try to use nodeExternals without whitelist ( Additionally, I'm not really sure if building on Ubuntu will work on AWS Lambda. They run Amazon Linux in their environment. I did some experiments with OpenCV in the past and I had to build the binary on an EC2 with Amazon Linux (latest version) to make it work when deployed. |
Actually I tried without the We used to push the node libs with native modules from Ubuntu 16.04 64 bit docker, it was working as expected, so I doubt the issues is not related to this. If I zip the entire Some observations are:
This is the library folder structure inside I was trying to avoid editing the library's |
@haridas The |
@HyperBrain Let me see I can package a sample test environment, so that the issue can be re-produceable using those files. |
Here is sample serverless project to re-create the problem. Please download and try it. Do following steps to reproduce the issue. cd sls_native_lib
npm install
cd jitr
npm install
cd ..
# Now packaging the sls project will give the error.
sls package
Please try with this and let me know if you have found any issue with the configurations with the webpack or serverless. |
@haridas Thanks for the sample 👍 . Hopefully that will help how to solve the problem. I think I can get some time to analyze it tomorrow. |
Just did a first. The |
UPDATE:
The main reason was that the file name resolver was not configured in webpack.conf.js. It has to be configured to use |
Yes adding the My updated webpack.config.js file const path = require("path");
const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
entry: slsw.lib.entries,
target: "node",
output: {
libraryTarget: "commonjs2",
path: path.resolve(__dirname, ".webpack"),
filename: "[name].js"
},
module: {
rules: [
{
test: /\.node$/,
loader: "node-loader"
}
]
},
resolve: {
extensions: [".js", ".json", ".node"]
},
mode: "none",
externals: [
nodeExternals({
whitelist: ["x509"]
})
],
plugins: [
//new CopyWebpackPlugin([
// {
// from: "jitr/node_modules/x509/build/Release/x509.node",
// to: "jitr/build/Release/x509.node",
// toType: "file"
// }
//])
],
devtool: "source-map"
}; |
Yes, you have to uncomment the copy plugin to get the binary library packaged. You have to check if the node file is sufficient or if you need to copy the whole Release folder to get all compiled binaries. webpack-386-native-modules.zip I also did some changes to the The webpack config also includes the correct "mode" setting to enable debugging when run locally, but using production mode otherwise. You can ignore the package.json changes. I only added serverless and sls-offline locally so that I could test better with specific versions. |
Thanks alot @HyperBrain, the new zip is working as expected and it's copying the Currently I'm facing issue like, the webpack bundled /***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {
try {global.process.dlopen(module,
"/project/serverless/jitr/node_modules/x509/build/Release/x509.node");
} catch(e) {throw new Error('Cannot open ' +
"/project/serverless/jitr/node_modules/x509/build/Release/x509.node" + ': ' + e);}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(5)(module))) Actually here the |
I think the path injection itself is done by the |
After trying multiple methods, it seems not initiative to go forward with the native library with lambda, it's more complex to manage and not fit for generic use-cases. Now I moved to In my case I have around 100 lambda functions, all are packaged with serverless ensuring no code duplication as much as possible in each lambda bundles. In which only handful of lambdas requires certificate handling support. |
Hi @haridas , good to hear that you found a feasible solution. Using |
Closing in favour of adding documentation as part of #495. |
This is a Bug Report
I created an stackoverflow question for the same, i'm pasting the full content from there.
The stackoverflow link: https://stackoverflow.com/questions/50188865/load-native-npm-x509-package-using-webpack-in-serverless
I'm testing the aws iot features using serverless framework. So for one usecase I wasn't to analyse the x509 certificates iot devices register with aws from aws lambdas, I saw npm package named
x509
to do it easily. It's a native package, so I'm building it in Ubuntu 64 bit box to make it compatible with aws environment.Issues is the webpack is not identifying this npm package even after my package importing it.
The error it saying is,
My package dir structure is,
My webpack config file
What might be going wrong here ?. I was looking for more debugging steps when doing webpack command, but here i'm using a serverless plugin named
serverless-webpack
to package and deploy the lambdas.Aws lambda have access to raw
openssl
command, if nothing works I have to use that command from nodejs to do the things.The text was updated successfully, but these errors were encountered: