OS:
Linux 4.9.85-38.58.amzn1.x86_64
React-pdf version:
0.7.6
Description:
Does anyone know how to run react-pdf in a lambda? I'm trying to install it(yarn add @react-pdf/core) but I get the following error:
yarn add v1.6.0
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
[1/1] ⠈ yoga-layout: NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
[-/1] ⠈ waiting...
[-/1] ⠈ waiting...
[-/1] ⠈ waiting...
error /home/ec2-user/environment/Commerce/node_modules/yoga-layout: Command failed.
Exit code: 1
Command: npm run build:node
Arguments:
Directory: /home/ec2-user/environment/Commerce/node_modules/yoga-layout
Output:
[email protected] build:node /home/ec2-user/environment/Commerce/node_modules/yoga-layout
npm run copy-sources && autogypi && node-gyp configure build
[email protected] copy-sources /home/ec2-user/environment/Commerce/node_modules/yoga-layout
! npm -s run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
make: Entering directory /home/ec2-user/environment/Commerce/node_modules/yoga-layout/build'
COPY Release/obj.target/nbind/geni/symbols.txt
CXX(target) Release/obj.target/nbind/sources/yoga/Utils.o
g++: error: unrecognized command line option ‘-std=c++14’
make: *** [Release/obj.target/nbind/sources/yoga/Utils.o] Error 1
make: Leaving directory/home/ec2-user/environment/Commerce/node_modules/yoga-layout/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/ec2-user/.nvm/versions/node/v8.10.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.9.85-38.58.amzn1.x86_64
gyp ERR! command "/home/ec2-user/.nvm/versions/node/v8.10.0/bin/node" "/home/ec2-user/.nvm/versions/node/v8.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /home/ec2-user/environment/Commerce/node_modules/yoga-layout
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build:node: npm run copy-sources && autogypi && node-gyp configure build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build:node script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
What's failing is Yoga. Did you try to find an issue about using Yoga in a lambda?
I'll create an issue in yoga and see what they say. Thanks.
Update: https://github.com/facebook/yoga/issues/763
I'm having the same issue with circleci:
error /home/ubuntu/cheddar_up_ui/node_modules/yoga-layout: Command failed.
Exit code: 1
Command: npm run build:node
Arguments:
Directory: /home/ubuntu/cheddar_up_ui/node_modules/yoga-layout
Output:
> [email protected] build:node /home/ubuntu/cheddar_up_ui/node_modules/yoga-layout
> npm run copy-sources && autogypi && node-gyp configure build
> [email protected] copy-sources /home/ubuntu/cheddar_up_ui/node_modules/yoga-layout
> ! npm -s run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
make: Entering directory `/home/ubuntu/cheddar_up_ui/node_modules/yoga-layout/build'
COPY Release/obj.target/nbind/geni/symbols.txt
CXX(target) Release/obj.target/nbind/sources/yoga/Utils.o
g++: error: unrecognized command line option ‘-std=c++14’
make: *** [Release/obj.target/nbind/sources/yoga/Utils.o] Error 1
make: Leaving directory `/home/ubuntu/cheddar_up_ui/node_modules/yoga-layout/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/opt/circleci/nodejs/v8.8.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at emitTwo (events.js:125:13)
gyp ERR! stack at ChildProcess.emit (events.js:213:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 3.13.0-144-generic
gyp ERR! command "/opt/circleci/nodejs/v8.8.1/bin/node" "/opt/circleci/nodejs/v8.8.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /home/ubuntu/cheddar_up_ui/node_modules/yoga-layout
gyp ERR! node -v v8.8.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build:node: `npm run copy-sources && autogypi && node-gyp configure build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build:node script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
@binchik I don't know if it would be helpful but here you can see an example of another project which runs on travis CI, don't know that much about circle but I think it is an good example which extra dependencies should be installed on the CI.
@jbovenschen that's funny I stumbled upon the same travis config and added the same to my circleci. It works now. Thanks.
If anyone has this issue, here are the commands to make yoga-layout compile for circleci:
dependencies:
pre:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install -qq g++-6
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
I am also having problems deloying react-pdf to aws lambda. So my understanding is that yoga-layout is a native module and needs to be compiled in the environment its going to run. So that is what I am trying to do but I am getting this error.
docker run -it -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 bash
bash-4.2# npm i
> [email protected] install /var/task/node_modules/yoga-layout
> npm run build:node
> [email protected] build:node /var/task/node_modules/yoga-layout
> npm run copy-sources && autogypi && node-gyp configure build
> [email protected] copy-sources /var/task/node_modules/yoga-layout
> ! npm -s run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)
make: Entering directory `/var/task/node_modules/yoga-layout/build'
make: Warning: File `nbind.target.mk' has modification time 0.28 s in the future
COPY Release/obj.target/nbind/geni/symbols.txt
CXX(target) Release/obj.target/nbind/sources/yoga/Utils.o
g++: error: unrecognized command line option ‘-std=c++14’
make: *** [Release/obj.target/nbind/sources/yoga/Utils.o] Error 1
So apparently this error is due the option -std=c++14 is not yet supported by the version of gcc provided by amazon linux.
Did anyone get it to work? Any clues on how solve this issue?
Hi @ferdinandsalis !
I'm pretty sure that's the cause of the issue too.
However, never tried to deploy react-pdf in a lambda, and don't have much experience working with lambda either. You cannot set the dependencies as @binchik said there?
Hey @diegomura. Thanks for chiming in. No problem. I am no aws lambda or linux expert. It seems I cant just install the newest version of gcc on Amazon Linux and I need to build it from source. I am doing this now …
Did you solve it @dberringer?
@ferdinandsalis I haven't had a chance to dive deeper into this yet but I will definitely post when I get it working. The issue is clearly with the version of gcc that is available in the lambda environment. I'm guessing it's running on the standard AWS Linux version which uses an older version of gcc(4.8.5) which doesn't support C++14. There is an Amazon linux 2 image you can use which comes with gcc7.3 preinstalled which should resolve the issue. Additionally, there may be a way to upgrade gcc on the current environment. I have also heard of folks precompiling binaries and including them as static resources with their lambda code so you wouldn't need to compile on deploy. I'm not a Linux guru and I haven't had a chance to work any of these options yet. This is as far as I have gotten so far. Hopefully that helps others.
So, I finally did get it to work by building a newer version of gcc from source. I am sure there is a better way but for now this works for me. I hope to have a more detailed explanation how to get react-pdf working on aws lambda at some later point.
I am so happy I can finally use react-pdf!
Glad to hear that @ferdinandsalis !
Do you mind sharing how you fix it, for documentation purposes? also to close this issue.
I promise I'll tackle this issue sometime in the future. Maybe ship react-pdf with the pre-bundled yoga asm, or similar, so we forget to build it every-time the lib gets installed
@ferdinandsalis can you share your solution with the group?
Yes sure. I will write something up as soon as I have time. Sorry, I am currently very busy …
Hey @ferdinandsalis , any chance you can share your fix? Don't need a huge explanation. Just the commands you used. Thanks.
Hey @dberringer sorry for the delay. I cant tell you the exact commands. However I can tell you what I did more or less — It has been a while.
npm install to install your dependencies and build yoga-layout for aws lambda.I hope this helps. Let me know if you have any more questions. I will soon improve my setup and thus revise this and hope to give more detail.
@ferdinandsalis do you know/test if this happens also on the new version?
@diegomura I will take a look
@diegomura If you want to know if installing @react-pdf/[email protected] in a lambda still causes the g++ error the answer is yes. I just tried it. Same result.
Having the same issue, when deploying to Netlify.
1:26:56 PM: error /opt/build/repo/node_modules/yoga-layout: Command failed.
1:26:56 PM: Exit code: 1
1:26:56 PM: Command: npm run build:node
1:26:56 PM: Arguments:
1:26:56 PM: Directory: /opt/build/repo/node_modules/yoga-layout
1:26:57 PM: Output:
1:26:57 PM: > [email protected] build:node /opt/build/repo/node_modules/yoga-layout
1:26:57 PM: > npm run copy-sources && autogypi && node-gyp configure build
1:26:57 PM: > [email protected] copy-sources /opt/build/repo/node_modules/yoga-layout
1:26:57 PM: > ! npm -s run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)
1:26:57 PM: make: Entering directory `/opt/build/repo/node_modules/yoga-layout/build'
1:26:57 PM: COPY Release/obj.target/nbind/geni/symbols.txt
1:26:57 PM: CXX(target) Release/obj.target/nbind/sources/yoga/Utils.o
1:26:57 PM: g++: error: unrecognized command line option ‘-std=c++14’
1:26:57 PM: make: *** [Release/obj.target/nbind/sources/yoga/Utils.o] Error 1
1:26:57 PM: make: Leaving directory `/opt/build/repo/node_modules/yoga-layout/build'
1:26:57 PM: gyp ERR! build error
@ferdinandsalis were you actually able to get this working? I have been able to compile yoga-layout with a newer version of GCC but it doesn't seem to matter because it still relies on a newer version of libstdc++.so.6 which isn't available in the lambda environment and I don't see how I could make changes to the lambda environment so my compiled yoga-layout will run. Any additional details on how you got this working would be much appreciated.
When I try to import react-pdf I get the following error:
/var/lang/lib/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /var/task/node_modules/yoga-layout/build/Release/nbind.node)
@dberringer I am so sorry to keep you hanging with this one 🙇♂️. I have not yet actually deployed this since I have stopped working on this feature for my app. However I will tackle this soonish …
@ferdinandsalis no worries. I have been banging on it and I'm not sure it's possible to do with just a lambda which is why I was curious if you got it working. I'm currently thinking I will wrap it up in a docker container which has a newer version of GCC. Then I can call ECS from my lambda. I was hoping not to have to do that but I don't see an alternative until AWS gets around to updating their lambda env. Happy to be proven wrong though. :)
I think the cause of error is building yoga every time the package gets installed. I thought that by using yoga-dom this may get fixed.
Pros
Cons
Thoughts?
Good points. I don't have any experience with the trade-offs of compiling on the fly vs going pre-compiled for a project like this so I'll let others who do weigh in on that point. It would greatly simplify things for me though. ;)
If you don't go precompiled I will probably end up calling AWS ECS from my lambda and use that to host the React-PDF build so that should work around the compilation issue.
@ferdinandsalis this should have been fixed by #364. Closing this for the moment, but feel free to report back if lambdas are having another issue
Most helpful comment
I think the cause of error is building yoga every time the package gets installed. I thought that by using yoga-dom this may get fixed.
Pros
Cons
Thoughts?