I am getting an error "Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x. Found bindings for the following environments: - Windows 64-bit with Node.js 10.x"
To solve this issue I have researched and could not solve the issue. I have tried the solutions from the following link, but never worked
https://stackoverflow.com/questions/37986800/node-sass-could-not-find-a-binding-for-your-current-environment
https://github.com/cypress-io/cypress/issues/1387
Can any one help me to solve the issue?
Hey @vijeeshvofox, could you tell us what you did to get this error? How did you install Cypress? What command did you run when you got this error? Where are you running this command from (a terminal? IDE?)? Thanks!
I have component which is included a sass file import './BlogDetailsComponent.style.sass'; . Then I created unit test for this component. I am getting an error, when I run this test file on cypress. Please find the screen shot of the error that I am getting

The test file is working when I comment the saas file from the test file.
To run the cypress I have used the command npm run test:e2e from visual code terminal.
For installation I have used the command npm install --save-dev cypress cypress-vue-unit-test and npm install --save-dev @cypress/webpack-preprocessor
How can we solve this issue?
i had similar problem before and resolved it by just doing a npm install sass manually. The conflict version is resolved and installation should be always correct in the environment after that
Please try:
npm rebuild node-sass
Closing as this does not seem related to Cypress directly. Open an issue in our webpack processor if necessary. Please comment with a fully reproducible example if you've determined it's a bug in Cypress and we will consider reopening.
@jennifer-shehane I came accross the same issue trying to run node-sass from cypress inside a docker
Dockerfile:
FROM cypress/base:10.15.3
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
# Copying node_modules, because they get installed at the build step, so we are garanteed that it is the latest version
COPY node_modules /app/node_modules
WORKDIR /app
# Installing cypress and all testing libraries
RUN npm i --save-dev cypress svelte-loader webpack @cypress/webpack-preprocessor cypress-svelte-unit-test
RUN npm rebuild node-sass
COPY ./dashboard /app/dashboard
COPY ./cypress/cypress.json /app
COPY ./cypress /app/cypress
webpack.config.js:
const sass = require('node-sass')
module.exports = {
resolve: {
// see below for an explanation
mainFields: ['svelte', 'browser', 'module', 'main']
},
module: {
rules: [
{
test: /\.(html|svelte)$/,
exclude: /node_modules/,
use: {
loader: 'svelte-loader',
options: {
hydratable: true,
cascade: false,
store: true,
hotReload: true,
style: ({ content, attributes }) => {
if (attributes.type !== 'text/scss') return
return new Promise((resolve, reject) => {
sass.render({
data: content,
includePaths: ['dashboard'],
sourceMap: true,
outFile: 'x' // this is necessary, but is ignored
}, (err, result) => {
if (err) return reject(err)
resolve({
code: result.css.toString(),
map: result.map.toString()
})
})
})
}
}
}
}
]
},
devtool: 'cheap-module-eval-source-map'
}
cypress/plugins/index.js:
const webpack = require('@cypress/webpack-preprocessor')
module.exports = on => {
const options = {
// send in the options from your webpack.config.js, so it works the same
// as your app's code
webpackOptions: require('../webpack.config.js')
}
on('file:preprocessor', webpack(options))
on('task', {
log (message) {
console.log(message)
return null
}
})
}
Error message:
Sending build context to Docker daemon 54.34MB
Step 1/10 : FROM cypress/base:10.15.3
---> db9a7020e198
Step 2/10 : COPY package.json /app/package.json
---> Using cache
---> 33c247d2bf21
Step 3/10 : COPY package-lock.json /app/package-lock.json
---> Using cache
---> 368b811dc17d
Step 4/10 : COPY node_modules /app/node_modules
---> Using cache
---> d9f7d145fbcc
Step 5/10 : WORKDIR /app
---> Using cache
---> c7722d1bd23f
Step 6/10 : RUN npm i --save-dev cypress svelte-loader webpack @cypress/webpack-preprocessor cypress-svelte-unit-test
---> Using cache
---> a11c1d55dfe5
Step 7/10 : RUN npm rebuild node-sass
---> Using cache
---> 35c88ad1eec8
Step 8/10 : COPY ./dashboard /app/dashboard
---> Using cache
---> 24049cf7d70a
Step 9/10 : COPY ./cypress/cypress.json /app
---> Using cache
---> edae15f5082b
Step 10/10 : COPY ./cypress /app/cypress
---> ca5798557651
Successfully built ca5798557651
Successfully tagged nsulate-monitoring-cypress:latest
+ docker run --rm my_docker_image:latest ./node_modules/.bin/cypress run
It looks like this is your first time using Cypress: 3.2.0
[22:38:45] Verifying Cypress can run /root/.cache/Cypress/3.2.0/Cypress [started]
[22:38:46] Verified Cypress! /root/.cache/Cypress/3.2.0/Cypress [title changed]
[22:38:46] Verified Cypress! /root/.cache/Cypress/3.2.0/Cypress [completed]
Opening Cypress...
The function exported by the plugins file threw an error.
We invoked the function exported by `/app/cypress/plugins/index.js`, but it threw an error.
Error: Missing binding /app/node_modules/node-sass/vendor/linux-x64-57/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 8.x
Found bindings for the following environments:
- Linux 64-bit with Node.js 10.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
at module.exports (/app/node_modules/node-sass/lib/binding.js:15:13)
at Object.<anonymous> (/app/node_modules/node-sass/lib/index.js:14:35)
at Object.<anonymous> (/app/node_modules/node-sass/lib/index.js:477:3)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/app/cypress/webpack.config.js:1:169)
at Object.<anonymous> (/app/cypress/webpack.config.js:47:3)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at module.exports.on (/app/cypress/plugins/index.js:6:21)
at Promise.try (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:62:12)
at tryCatcher (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
Note: I have tried installing node-sass directly inside the Docker image instead of copying my node_modules over, it didn't change anything because if you run node -v in the docker before the install step it shows node v10.15.3
My understanding is that the Cypress engine must be running on node v8.X even if we use the cypress:10.15.3 Docker image ....
Note 2: If I remove sass from my svelte components, and the set up in webpack config, the tests are passing. So the set up is working, it is really just an issue of node bindings
Yes, Cypress runs on node v8.x https://github.com/cypress-io/cypress/blob/master/.node-version#L1
@jennifer-shehane So, any advice on how to use Cypress to test a framework like Svelte, React, Vue, etc, etc. that uses Sass bindings and node 10 ?
Since we have to go through the Cypress pluging to load our components, our own version of node-sass has bindings for node 10.X but it is being loaded by Cypress which has version 8.X
I'm also running into this issue and curious about workarounds. It seems being able to run a simple npm rebuild node-sass could fix it, but there's no hook to run that before test execution that I can find.
Strangely I'm able to run my tests without issue when I use the headed electron app and "Run all tests". But not in headless mode with cypress run I still get the error. It's not entirely clear what the difference is.
So here is what happens:
node-sass for Node v8 and fails...Suggested workaround:
BTW the same issue affects anyone using native dependencies, for example connecting to a database requires a native dependency usually
Makes sense thanks for the explanation. It gave me an idea to workaround my problem by creating a TEST babel environment config to use while running tests which doesn't include plugins/presets which use node-sass. It fixes my problem for now.
@bahmutov is this issue resolved now that users can use a custom Node version?
Yes, it has been resolved @flotwig
Anyone hitting the Node version mismatch, please use configuration option https://on.cypress.io/configuration#Node-version to execute the plugins and tasks using the system Node version.
yes Add,
{
"nodeVersion":"system"
}
in cypress.json
Most helpful comment
Yes, it has been resolved @flotwig
Anyone hitting the Node version mismatch, please use configuration option https://on.cypress.io/configuration#Node-version to execute the plugins and tasks using the system Node version.