Home > Mobile >  Heroku fails during build with Error: Node Sass does not yet support your current environment: Linux
Heroku fails during build with Error: Node Sass does not yet support your current environment: Linux

Time:12-18

Ruby 2.7.4 Rails 6.1.4.1

note: in package.json the engines key is missing in my app

Heroku fails during build with this error

this commit is an empty commit on top of exactly a SHA that I was successful at pushing yesterday (I've checked twice now) so I suspect this is a platform problem or somehow the node-sass got deprecated or yanked yesterday?

how can I fix this?

remote:        
remote:        ERROR in ./app/javascript/require_bootstrap.scss
remote:        Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
remote:        ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
**remote:        Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (93)**
remote:        For more information on which environments are supported please see:
remote:        https://github.com/sass/node-sass/releases/tag/v4.14.1
remote:            at module.exports (/tmp/build_1c436dcf/node_modules/node-sass/lib/binding.js:13:13)
remote:            at Object.<anonymous> (/tmp/build_1c436dcf/node_modules/node-sass/lib/index.js:14:35)
remote:            at Module._compile (/tmp/build_1c436dcf/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
remote:            at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

CodePudding user response:

As per Heroku's switching default node from 14 to 16 in Dec 2021 (see https://devcenter.heroku.com/changelog-items/2306).

for apps affected, the base heroku/ruby buildpack updated the Node version from the Node 14 to Node 16 which is not compatible with the version of Node Sass locked in at the version of Webpack we're using.

To fix it I needed to do two things:

  1. Specify the 14.x Node version in package.json.
# In package.json
{
  # ...
  "engines": {
    "node": "14.x"
  },
  # ...
}
  1. Add the heroku/nodejs buildpack before the heroku/ruby buildpack. You can do this in the web interface or with the command line. Here is the command for the CLI:
$ heroku buildpacks:add heroku/nodejs -i 1 -a YOUR-APP-NAME

With the NodeJS buildpack running first, it will look at the package.json file and respect that when choosing which version of Node to install. Then the Ruby buildpack will run and since a version of Node already exists it will just use that and everything should work as before.

  • Related