Recommendations for Server for Next.js
Unanswered
Chum salmon posted this in #help-forum
Chum salmonOP
On an API route within my application, I'm using a text parsing npm module that runs a shell command. This works fine on my local machine, but when I deployed to Vercel, using the route throws an error because of the shell command.
I read online that Vercel is an ephemeral, serverless environment with limited shell command support. Because of this it seems recommended to move the text parsing logic to a separate, dedicated server and access this via an API call.
Does anyone have recommendations for server hosts? I just need something simple and free. I'm leaning towards DigitalOcean, but have never used it before. I use heroku on another small project, but ended up paying for it.
Or would it be simpler to not host on Vercel?
I read online that Vercel is an ephemeral, serverless environment with limited shell command support. Because of this it seems recommended to move the text parsing logic to a separate, dedicated server and access this via an API call.
Does anyone have recommendations for server hosts? I just need something simple and free. I'm leaning towards DigitalOcean, but have never used it before. I use heroku on another small project, but ended up paying for it.
Or would it be simpler to not host on Vercel?
10 Replies
Northeast Congo Lion
what shell command does it need?
Chum salmonOP
The module is mecab-async, it takes a Japanese sentence and returns the "words" in the sentence. You can view the module here https://www.npmjs.com/package/mecab-async?activeTab=code in the mecab.js file. I believe the error is triggering from line 35. It tries running this.command, which is mecab, but then the error message says mecab is not found. I believe this is a shell command because sq is from the shell-quote module.
The exact error message is ""Command failed: echo <Whatever Japanese text> | mecab\n/bin/sh: line 1: mecab: command not found\n" This is only appearing on the vercel deployment. It works on my machine
Northeast Congo Lion
So on your machine you have a program called
mecab. I don't know how much luck you're going to have to find a standard deployment solution with that binary available. I think you're going to need to create some custom docker image that installs it, then deploy to some place that runs docker images like fly.io.Or find a module that does the work without calling an external program.
Chum salmonOP
@Northeast Congo Lion Can you help me understand the issue if you know? I thought the problem was Vercel can't run the shell command because it's serverless so it's throwing an error. What do you mean by finding a deployment solution with that binary?
mecab-async is an npm module that Vercel should install for deployment. Wouldn't it also install the shell-quote dependecy?
Northeast Congo Lion
it is running a program called
mecab. Somehow, that exists on your local machine because you or someone who administers it installed it. It is not a "standard" program you'll find on any hosting environments.As for having the node module install the needed binary, maybe they do and it only works on some specific hardware. The module is 7 years old and not even a release version so you're really playing with fire if your app is depending on this library and you don't know how to fix it when it breaks.
Chum salmonOP
Ok, thank you @Northeast Congo Lion for pointing me in the right direction. I didn't know about binary executables, so I would've been going in circles.
So, to recap, it's not working because mecab-async needs to run some code directly on a computer's cpu and that's not available in a serverless environment. When I installed mecab-async it probably installed the mecab binary on my computer, which is why it works on my machine but doesn't on vercel.
My application is in the pre-alpha maybe alpha stage. I really only wanted to deploy so I could share it with a few people. But I'll look into mecab alternatives. Thanks!
So, to recap, it's not working because mecab-async needs to run some code directly on a computer's cpu and that's not available in a serverless environment. When I installed mecab-async it probably installed the mecab binary on my computer, which is why it works on my machine but doesn't on vercel.
My application is in the pre-alpha maybe alpha stage. I really only wanted to deploy so I could share it with a few people. But I'll look into mecab alternatives. Thanks!