node-sass icon indicating copy to clipboard operation
node-sass copied to clipboard

Cannot use relative paths for sass binary path

Open wittibs opened this issue 9 years ago • 3 comments

If I specify a sass_binary_path variable with a relative path in a local .npmrc file, the install/build process won't pick it up properly.

From lib/extensions.js:

function hasBinary(binaryPath) {
  return fs.existsSync(binaryPath);
}

fs.existsSync checks for existence of directory/file based on the directory in which node process was started.

From lib/binding.js:

module.exports = function(ext) {
  if (!ext.hasBinary(ext.getBinaryPath())) {
    if (!ext.isSupportedEnvironment()) {
      throw new Error(errors.unsupportedEnvironment());
    } else {
      throw new Error(errors.missingBinary());
    }
  }

  return require(ext.getBinaryPath());
};

The require() near the bottom tries to load the binary with respect from the current directory binding.js exists in. This is at odds with the ext.hasBinary() call above.

OS/platform info below.

  • NPM version (npm -v): 5.3.0
  • Node version (node -v): 8.4.0
  • Node Process (node -p process.versions): { http_parser: '2.7.0', node: '8.4.0', v8: '6.0.286.52', uv: '1.13.1', zlib: '1.2.11', ares: '1.10.1-DEV', modules: '57', nghttp2: '1.22.0', openssl: '1.0.2l', icu: '59.1', unicode: '9.0', cldr: '31.0.1', tz: '2017b' }
  • Node Platform (node -p process.platform): darwin
  • Node architecture (node -p process.arch): x64
  • node-sass version (node -p "require('node-sass').info"): 4.5.3
  • npm node-sass versions (npm ls node-sass): 4.5.3

wittibs avatar Aug 27 '17 23:08 wittibs

As I mentioned in PR #2108, I don't think this should be a feature. The implementation to this would be non-deterministic and hackish at best.

wittibs avatar Nov 13 '17 03:11 wittibs

I am having the same issue using local .npmrc file on Windows and relative path,

sass_binary_path=".\binaries\win32-x64-51_binding.node"

reports that "Cannot find module 'binaries/win32-x64-51_binding.node'"

HeavenlyHost avatar Feb 08 '18 08:02 HeavenlyHost

The relative path is working, just you need to know where the path starts. :) getBinaryDir is defined in node_modules/node-sass/lib/extensions.js

So... sass_binary_dir "../../" points to node_modules

goranovs avatar Nov 05 '18 15:11 goranovs