Skip to content
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

Module initialization error on using with AWS lambda #3

Closed
tgensol opened this issue Jan 22, 2019 · 11 comments
Closed

Module initialization error on using with AWS lambda #3

tgensol opened this issue Jan 22, 2019 · 11 comments
Labels

Comments

@tgensol
Copy link

tgensol commented Jan 22, 2019

Hi there,

I tried to use your package on a serverless function (AWS Lambda nodeJs 8.10), but I am getting this error :

module initialization error: Error
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/node_modules/shorter/index.js:3:17)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)

I found this issue lovell/sharp#1306 for Sharp, so I tried to do it.

I am deploying my function throught circle-ci which is using these commands (among others) :

- image: lambci/lambda:build-nodejs8.10
- run: npm install --arch=x64 --platform=linux --target=8.10.0 shorter

The last one produced this log :


#!/bin/bash -eo pipefail
npm install --arch=x64 --platform=linux --target=8.10.0 shorter

> shorter@0.3.1 install /root/repo/node_modules/shorter
> node-gyp rebuild

make: Entering directory `/root/repo/node_modules/shorter/build'
  CC(target) Release/obj.target/shoco/src/shoco/shoco.o
  AR(target) Release/obj.target/src/shoco.a
  COPY Release/shoco.a
  CXX(target) Release/obj.target/shorter/src/shorter.o
  SOLINK_MODULE(target) Release/obj.target/shorter.node
  COPY Release/shorter.node
make: Leaving directory `/root/repo/node_modules/shorter/build'
npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ts-jest@23.10.5 requires a peer of jest@>=22 <24 but none is installed. You must install peer dependencies yourself.
npm WARN chromeless-remotechrome-service@1.3.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ shorter@0.3.1
added 2 packages in 6.862s

Any suggestions ? :)

Thanking you in advance

@tgensol tgensol changed the title Module initialization error on using Sharp in AWS lambda Module initialization error on using with AWS lambda Jan 22, 2019
@lovell
Copy link
Owner

lovell commented Jan 22, 2019

If you're using a code bundler such as webpack then you'll need to ensure native modules such as this are part of its externals config. https://webpack.js.org/configuration/externals/

@tgensol
Copy link
Author

tgensol commented Jan 22, 2019

Hi @lovell ,

Thank you a lot for your quick reply,

I am using Webpack indeed, and https://github.com/liady/webpack-node-externals for externals.

I tried to whitelist 'shorter' with :

 externals: [nodeExternals({
        whitelist: ['shorter']
    })],

But I am getting these error :

ERROR in ./node_modules/shorter/index.js
Module not found: Error: Can't resolve './build/Release/shorter' in '/root/repo/node_modules/shorter'
 @ ./node_modules/shorter/index.js 3:16-50
 @ ./src/export.ts

I am missing something... If you have any idea,

Thank you

@lovell
Copy link
Owner

lovell commented Jan 22, 2019

According to the docs for the webpack-node-externals module, whitelist will include the module, which is the opposite of what you want.

@tgensol
Copy link
Author

tgensol commented Jan 22, 2019

Right I misunderstood your reply, I thought I needed to include it

So I was getting the error of my first post with using externals: [nodeExternals({})], which does not include any lib of node_modules

@lovell
Copy link
Owner

lovell commented Jan 22, 2019

Is the node_modules/shorter/build/Release/shorter.node file included in the resultant zip file?

@sharstream
Copy link

Hey guys, thanks posting this issue. I am facing the same issue with my serverless when I deploy sharp to my lambda function. I am started and I cannot be able to exe sharp.node and pre-compiled files in serverless with webpack nor in AWS lamda. Any throughs how I can outcome this issue, I'm running in Mac?

@lovell
Copy link
Owner

lovell commented Mar 13, 2019

@sharstream This is the shorter repo - you want https://github.com/lovell/sharp/search?q=lambda+webpack&type=Issues

@sharstream
Copy link

sharstream commented Mar 15, 2019

Sorry the delay response @lovell. I took a harder look to those issues: #1258, #1306, serverless-webpack#396. I'm using webpack same as #396 but with node8.10. My machine's running on darwin-x64 and every deployments is through a gitlab ci-pipeline in linux-x64. I'm using the same webpack.config.js and the problem still persist, I tried different approaches, I think my last resource is run a docker image before bundling with webpack. Is there any further steps I can follow? TIA Below is my errors prompted:
Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (/var/task/node_modules/ajv/lib/compile/resolve.js:3:11) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (/var/task/index.js:3:30) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

$ rm -rf node_modules/sharp && $ npm install --arch=x64 --platform=linux --target=8.10.0 sharp

sharp@0.21.3 install /builds/aws/microservices/maio-service-live/node_modules/sharp
(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

@lovell
Copy link
Owner

lovell commented Mar 15, 2019

@sharstream This is not the sharp repo.

@sharstream
Copy link

sharstream commented Mar 15, 2019

Thanks for your quick response. Please refer to #1261 and #396

@lovell
Copy link
Owner

lovell commented Mar 15, 2019

@sharstream This is the shorter repo. If you have a question about sharp then please create a new issue on the sharp repo at https://github.com/lovell/sharp/issues/new

@lovell lovell closed this as completed Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants