vercel / micro

Asynchronous HTTP microservices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with deploying a micro service

ForzaZzh opened this issue · comments

Hello,
I build a small micro service using pdfbox and java modules. When I run it locally everything is fine but when I try to deploy it it gives me the error below:

`> [node-java] Error: not found: javac

gyp: Call to 'node findJavaHome.js' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)
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.13.0-1011-gcp
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/nowuser/src/node_modules/node-pdfbox/node_modules/java
gyp ERR! node -v v8.11.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! not ok
npm WARN forza_io_test_pdfbox@3.0.0 No repository field.
npm WARN forza_io_test_pdfbox@3.0.0 No license field.
Error! Build failed`

package.json
{ "name": "pdfbox_test", "version": "3.0.0", "description": "pdfbox_test", "author": "zzh", "main": "index.js", "scripts": { "start": "micro", "dev": "micro-dev" }, "dependencies": { "axios": "latest", "java": "^0.9.1", "lodash": "latest", "micro": "latest", "micro-cors": "latest", "moment": "^2.20.1", "node-pdfbox": "^0.1.9" }, "devDependencies": { "micro-dev": "latest" } }

Could you provide a full reproduction? I'm pretty sure it's unrelated to micro's functioning though 🤔

it's a simple post request, sending pdf document

`const axios = require('axios')
const _ = require('lodash')
const { json } = require('micro')
const { send } = require('micro')
const { createError } = require('micro')
const microCors = require('micro-cors')
const moment = require('moment')
const java = require('java')
const Document = require('node-pdfbox')

const cors = microCors({ allowMethods: ['POST'] })

const testPdfBox= async (req, res) => {
let output = {}
let myDoc = Document.loadSync('./testdoc.pdf')
let page = myDoc.getPageSync(0)

output.extract_result = page.getTextSync()

output.result = 'OK'

statusCode = 200

// Return Response Object
send(res, statusCode, output)

}

module.exports = cors(testPdfBox)`

@ForzaZzh this is not an issue with micro.
You can see your error here https://github.com/joeferner/node-java#installation

I believe that now's standard image doesn't have java installed, so you have to deploy it with a Dockerfile.

Create a Dockerfile in your project root folder with something like

FROM joeferner/node-java
COPY . /src
WORKDIR "/src"
RUN npm install --production
EXPOSE 3000

# Startup
ENTRYPOINT npm start

@maccyber is correct 👍