cheatcode / nodejs-server-boilerplate

Back-end boilerplate for building web applications, based on Node.js.
127 stars 46 forks source link

Failed at the nodejs-server@ build script. for Heroku Deployment #7

Open pisacode opened 3 years ago

pisacode commented 3 years ago

Hi thanks for this amazing resources.

I am trying to upload this backend project to heroku howerver I am receiving a Failed at the nodejs-server@ build script. error. There is no other error code.

I have tried so many things to fix this error by going over this docs https://devcenter.heroku.com/articles/troubleshooting-node-deploys however no luck.

Everything works fine on local env.

Is there anyone succeded at deployin this repo to heroku?

Thanks

rglover commented 3 years ago

Hey @pisacode are you doing the build locally or via Heroku? It sounds like there may be a missing dependency...

pisacode commented 3 years ago

Hey @rglover I have run the build locally and it works just fine, for the Heroku part I have added heroku config:set NPM_CONFIG_PRODUCTION=false to be able to use devDeps. But still getting a very broad error message as Failed at the nodejs-server@ build script

I have also open a ticket on Heroku in case they might point me in the right direction. In the mean time I will just build it locally and then push the build to the remote. If I find a solution I will keep this issue updated.

Many thank for all your effort on this new repo.

rglover commented 3 years ago

Hey @pisacode out of curiosity do you see anything in the error output about the .app folder? Just spotted something while writing a tutorial that may be the cause.

rglover commented 3 years ago

Following up on this. I just worked through a deployment using Dokku which uses Heroku buildpacks by default for builds. I can confirm that for some reason, the build step fails when running the buildpack. I was able to get around this by just using a Dockerfile. It looks like that may be possible w/ Heroku but you'd have to confirm.

If it is, I can add in an example Dockerfile to get it working.

inkiltie commented 3 years ago

I'm on the same page here. Tried bunch of workarounds but receiving this error:

remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! nodejs-server@0.0.1 build: `cross-env NODE_ENV=production webpack --config webpack.config.js`
remote: npm ERR! Exit status 1
remote: npm ERR! 
remote: npm ERR! Failed at the nodejs-server@0.0.1 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
pisacode commented 3 years ago

Hi, @rglover Docker file would be much appreciated, because we couldnt deploy our app to heroku after trying every possible option.

rglover commented 3 years ago

Here is the Dockerfile I've used to test Kubernetes deploys of the boilerplate. Keep in mind, this is using an Alpine Linux distribution so certain Linux/binary dependencies may not be available.

FROM node:12.18.3-alpine

ARG NODE_ENV
ARG APP_SETTINGS

# NOTE: Copy contents of app into Docker container.
COPY . .

# NOTE: Add necessary dependencies for building bcrypt on Alpine linux. These are not
# included by default and cause a runtime error if not installed.
#
# See: https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions#alpine-linux-based-images
RUN apk --no-cache add --virtual builds-deps build-base python

# NOTE: Install Chromium for use with Puppeteer.
ENV CHROME_BIN=/usr/bin/chromium-browser
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

RUN apk add --no-cache chromium
RUN apk add git

# NOTE: Install dependencies in container.
RUN npm install --production

# NOTE: Rebuild bcrypt internally so it runs properly in the container.
RUN npm rebuild bcrypt --build-from-source

RUN npm install -g pm2

ENV PORT=5001
ENV NODE_ENV=$NODE_ENV
ENV APP_SETTINGS=$APP_SETTINGS

EXPOSE 5001

CMD ["pm2-runtime", "dist/index.js", "-i", "'max'", "--env", "production"]

I just place this file at the root of my project and then do a docker build -f path/to/Dockerfile.

rglover commented 3 years ago

I should also note that I use PM2 for running Node in production. You don't have to do this but I've found it helpful for handling process crashes/restarts.