Rescript-compiler: Docker/Heroku deploy - "spawnSync /tmp/build_/node_modules/bs-platform/bin/bsb.exe ENOENT"

Created on 7 Dec 2017  Â·  12Comments  Â·  Source: rescript-lang/rescript-compiler

Hi! I'm having difficulty deploying a Reason/BS app built on bs-express to Heroku. I've created an example app that demonstrates the problem with a "Deploy to Heroku" button.

If you try out the build, you should see this output:

-----> Node.js app detected
-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  8.x.x
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  1.x.x

       Resolving node version 8.x.x...
       Downloading and installing node 8.9.2...
       Using default npm version: 5.5.1
       Resolving yarn version 1.x.x...
       Downloading and installing yarn (1.3.2)...
       Installed yarn 1.3.2
-----> Restoring cache
       Skipping cache restore (not-found)
-----> Building dependencies
       Installing node modules (yarn.lock)
       yarn install v1.3.2
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       warning "bs-apollo-server-express > [email protected]" has incorrect peer dependency "graphql@^0.10.5".
       [4/4] Building fresh packages...
       Done in 26.40s.
       Running heroku-postbuild (yarn)
       yarn run v1.3.2
       $ yarn build
       $ bsb -make-world
Error: spawnSync /tmp/build_aff0a6152854f19869c2a33dd17019c6/bkonkle-reason-express-heroku-528fd92/node_modules/bs-platform/bin/bsb.exe ENOENT
error Command failed with exit code 2.
       info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
       info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
-----> Build failed

       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys

       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/

       Love,
       Heroku

 !     Push rejected, failed to compile Node.js app.
 !     Push failed

It looks like it's having trouble finding bsb in the buildpack environment, but I've tried numerous ways of making sure bs-platform is installed both locally and globally in the build environment.

Surprisingly, I've tried this same build in a Docker environment using the node-8 alpine image, with the same ENOENT result. I also tried with a Docker image tailored to BuckleScript, with an entirely different error that doesn't seem to be related.

Any help tracking this down would be much appreciated! I'm hoping to have a deployment up and running for a client within a couple weeks.

Thanks!

need feedback

All 12 comments

Oh - I've also tried just running the bsb build on my local machine and committing the .js files (which is a practice I'm continuing because of convenience), but dependencies like bs-express and bs-apollo-server-express don't include their built js so the server execution fails when it tries to require their .js files.

@bkonkle can you try these two commands see the output

which bsb
ls `which bsb`

Thanks for the quick response!

I updated my "heroku-postbuild" hook in the package.json file to this: which bsb && ls `which bsb` && yarn build. bsb is definitely there:

remote:        Running heroku-postbuild (yarn)
remote:        yarn run v1.3.2
remote:        $ which bsb && ls `which bsb` && yarn build
remote:        /tmp/build_6b0fc94b88d291a61bfb0137d7e1bb4e/node_modules/.bin/bsb
remote:        /tmp/build_6b0fc94b88d291a61bfb0137d7e1bb4e/node_modules/.bin/bsb
remote:        $ bsb -make-world
remote: Error: spawnSync /tmp/build_6b0fc94b88d291a61bfb0137d7e1bb4e/node_modules/bs-platform/bin/bsb.exe ENOENT
remote: error Command failed with exit code 2.

Here's the full log output:


Click to expand

reason-express-heroku master 0m ▲ ➜ git push heroku master
Counting objects: 45, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (45/45), done.
Writing objects: 100% (45/45), 60.48 KiB | 4.65 MiB/s, done.
Total 45 (delta 11), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  8.x.x
remote:        engines.npm (package.json):   unspecified (use default)
remote:        engines.yarn (package.json):  1.x.x
remote:
remote:        Resolving node version 8.x.x...
remote:        Downloading and installing node 8.9.2...
remote:        Using default npm version: 5.5.1
remote:        Resolving yarn version 1.x.x...
remote:        Downloading and installing yarn (1.3.2)...
remote:        Installed yarn 1.3.2
remote:
remote: -----> Restoring cache
remote:        Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote:        Installing node modules (yarn.lock)
remote:        yarn install v1.3.2
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning "bs-apollo-server-express > [email protected]" has incorrect peer dependency "graphql@^0.10.5".
remote:        [4/4] Building fresh packages...
remote:        Done in 19.78s.
remote:        Running heroku-postbuild (yarn)
remote:        yarn run v1.3.2
remote:        $ which bsb && ls `which bsb` && yarn build
remote:        /tmp/build_6b0fc94b88d291a61bfb0137d7e1bb4e/node_modules/.bin/bsb
remote:        /tmp/build_6b0fc94b88d291a61bfb0137d7e1bb4e/node_modules/.bin/bsb
remote:        $ bsb -make-world
remote: Error: spawnSync /tmp/build_6b0fc94b88d291a61bfb0137d7e1bb4e/node_modules/bs-platform/bin/bsb.exe ENOENT
remote: error Command failed with exit code 2.
remote:        info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote: error Command failed with exit code 1.
remote:        info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !   Push rejected to reason-express-heroku.
remote:
To https://git.heroku.com/reason-express-heroku.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/reason-express-heroku.git'

I'm still having this issue with Docker as well. Here's the my current dockerfile: https://github.com/ecliptic/reason-graphql-docker/blob/master/Dockerfile

Here are the results:

[5/5] Building fresh packages...
Done in 25.36s.
Removing intermediate container eea040234ace
 ---> 2c6355ab38f5
Step 11/13 : COPY . .
 ---> 3dde539cc24c
Step 12/13 : RUN yarn build
 ---> Running in c92317fd9c74
yarn run v1.3.2
$ bsb -make-world
Error: spawnSync /usr/src/app/node_modules/bs-platform/bin/bsb.exe ENOENT
error Command failed with exit code 2.

Here's the full output:


Click to expand

reason-express-heroku master 0m ➜ docker build .
Sending build context to Docker daemon  416.8kB
Step 1/13 : FROM node:8
 ---> 4174ede1290d
Step 2/13 : WORKDIR /
 ---> Using cache
 ---> 87fb482013d5
Step 3/13 : ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.1/dumb-init_1.1.1_amd64 /usr/local/bin/dumb-init
Downloading  42.65kB/42.65kB
 ---> Using cache
 ---> 0ada11e8aa34
Step 4/13 : RUN addgroup --system app   && adduser --system --group app     && chmod +x /usr/local/bin/dumb-init     && mkdir -p /usr/src/app   && chown -R app:root /usr/src/app   && chmod -R 0770 /usr/src/app;
 ---> Using cache
 ---> 851d8c50ce02
Step 5/13 : USER app
 ---> Using cache
 ---> d279ee16f785
Step 6/13 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 75f27ee1fcda
Step 7/13 : ENV NODE_ENV=production
 ---> Using cache
 ---> b4e574b125e6
Step 8/13 : COPY package.json .
 ---> 1249a313b130
Step 9/13 : COPY yarn.lock .
 ---> 02e1b7b9ca28
Step 10/13 : RUN yarn --prod
 ---> Running in eea040234ace
yarn install v1.3.2
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
warning "bs-apollo-server-express > [email protected]" has incorrect peer dependency "graphql@^0.10.5".
[5/5] Building fresh packages...
Done in 25.36s.
Removing intermediate container eea040234ace
 ---> 2c6355ab38f5
Step 11/13 : COPY . .
 ---> 3dde539cc24c
Step 12/13 : RUN yarn build
 ---> Running in c92317fd9c74
yarn run v1.3.2
$ bsb -make-world
Error: spawnSync /usr/src/app/node_modules/bs-platform/bin/bsb.exe ENOENT
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn build' returned a non-zero code: 1

I'm getting further in my troubleshooting. What I think is happening is that the installation of bs-platform is failing behind the scenes because of dependencies that are needed for things like ninja-build. On alpine in Docker, the following RUN line _almost_ fixes up my build process: apk add --upgrade --no-cache sudo make patch gcc g++ python

I imagine the trouble on Heroku is similar, and I'll need to add some buildpacks to solve.

Okay, for anyone who finds this issue later, here's a workaround:

Build your container locally. Do not run yarn build or bsb -make-world in the Dockerfile. Use something like this in your .dockerignore:

# Selective node modules ignore
node_modules/*
!node_modules/bs-express/lib/js/
!node_modules/bs-apollo-server-express/lib/js/

Then you can push your image to a container registry on Heroku, AWS, Google, etc - or to a private Docker Hub account. For example, in Heroku you would use the container:push command with web as the process type.

This is fine pre-release, but once an application is out in production I'll want to start using Heroku review apps, and eventually I'll be moving everything out to Kubernetes. For both of those purposes, I need to be able to build remotely based on just the git tree. I'd definitely appreciate any help you or the community could provide there!

Thank you so much for sharing such an awesome project!

More debug info here, from a built Docker container:

/usr/src/app $ npx which bsb
/usr/src/app/node_modules/.bin/bsb
/usr/src/app $ npx bsb -make-world
Error: spawnSync /usr/src/app/node_modules/bs-platform/lib/bsb.exe ENOENT
/usr/src/app $ cd node_modules/bs-platform/lib/
/usr/src/app/node_modules/bs-platform/lib $ ls
Makefile                   bsdep.d                    reactjs_jsx_ppx_2.darwin
amdjs                      bsdep.ml                   reactjs_jsx_ppx_2.win
bsb                        bsdep.mli                  reactjs_jsx_ppx_v2.ml
bsb.d                      bspp.d                     reactjs_jsx_ppx_v2.mli
bsb.darwin                 bspp.ml                    refmt.darwin
bsb.ml                     bspp.mli                   refmt.win
bsb.mli                    bsppx.d                    refmt3.darwin
bsb.win                    bsppx.darwin               refmt3.win
bsb_helper.d               bsppx.ml                   refmt_main.ml
bsb_helper.darwin          bsppx.mli                  refmt_main.mli
bsb_helper.ml              bsppx.win                  refmt_main3.ml
bsb_helper.mli             bsrefmt                    refmt_main3.mli
bsb_helper.win             config_whole_compiler.ml   whole_compiler.d
bsc                        config_whole_compiler.mli  whole_compiler.ml
bsc.darwin                 es6                        whole_compiler.mli
bsc.win                    js
bscc                       ocaml
/usr/src/app/node_modules/bs-platform/lib $

bsb.exe doesn't exist, but bsb does. Any idea why?

Seems postinstall is not triggered, bsc.exe is not found either

do you have any luck?

I can confirm the (symlinked?) bs-platform dep can get into a state where postinstall is not triggered. Removing node_modules and installing seems to work, but can cause a problem for the linked bs-platform installed by bsb -init ....

@bobzhang I'm getting the same error on Ubuntu 18, why is trying to use bsc.exe ? I'm on linux not windows.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andares picture andares  Â·  5Comments

jordwalke picture jordwalke  Â·  4Comments

cknitt picture cknitt  Â·  5Comments

glennsl picture glennsl  Â·  3Comments

alexfedoseev picture alexfedoseev  Â·  5Comments