node-sass: EINVAL: invalid argument, open '/code/node_modules/node-sass/package.json'

Failure upon running the npm install command within a freshly cloned project.

  • NPM version (npm -v): 6.4.1
  • Node version (node -v): v8.12.0
  • Node Process (node -p process.versions):
{ http_parser: '2.8.0',
  node: '8.12.0',
  v8: '6.2.414.66',
  uv: '1.19.2',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  nghttp2: '1.32.0',
  napi: '3',
  openssl: '1.0.2p',
  icu: '60.1',
  unicode: '10.0',
  cldr: '32.0',
  tz: '2017c' }
  • Node Platform (node -p process.platform): linux
  • Node architecture (node -p process.arch): x64
  • node-sass version (node -p "require('node-sass').info"): Not applicable (never successfully installed.)
  • npm node-sass versions (npm ls node-sass after trying to run npm install):
root:/code# npm ls node-sass
my_project@0.0.0 /code
`-- @angular-devkit/build-angular@0.10.2
  `-- UNMET DEPENDENCY node-sass@4.9.3

npm ERR! missing: node-sass@4.9.3, required by @angular-devkit/build-angular@0.10.2

My experience is as follows (I can post additional info of my project, if required.)

Side-notes:

  • node-sass fails to install within my ubuntu-16.04 based docker image (microsoft/vsts-agent) and this environment is what this issue concerns.
  • node-sass successfully installs on my windows host machine. My windows environment has same major versions of my docker container’s environment (node + npm) and the project’s source is the same on windows as what I am trying to developer against in the docker container.
root:/code# npm install
npm WARN (deprecated warnings)

> uws@9.14.0 install /code/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0

> node-sass@4.9.3 install /code/node_modules/node-sass
> node scripts/install.js

fs.js:646
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EINVAL: invalid argument, open '/code/node_modules/node-sass/package.json'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at Object.Module._extensions..json (module.js:670:20)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/code/node_modules/node-sass/lib/extensions.js:7:9)
    at Module._compile (module.js:653:30)

npm WARN (rollback warnings here)
npm WARN (peer dependency warnings here)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.9.3 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.9.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-10-23T17_41_19_761Z-debug.log

root:/code#

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 18 (2 by maintainers)

Most upvoted comments

I’m aware this issue has been closed, but it’s still a problem for me.

It appears that this has been closed under the premise that this is a problem with npm, node, docker, windows, or some other utility. Have issue(s) been filed in the appropriate repositories so that I can track them? Can we reference those issues so others, like me, that stumble here can find the appropriate issues?

In fact, @gwenl, the accepted answer here is what is now working for me: https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder

It seems for me that the synchronization between my Windows host and Linux container was mixing a lot up.

If you want to have subdirectories ignored by docker-compose but persistent, you can do the following in docker-compose.yml:

volumes:
  node_modules:
services:
  server:
    volumes:
      - .:/app
      - node_modules:/app/node_modules

This will mount your current directory as a shared volume, but mount a persistent docker volume in place of your local node_modules directory. This is similar to the answer by kernix, but this will allow node_modules to persist between docker-compose up runs, which is likely the desired behavior.

Hello,

I have a Windows 10 with docker and I use the following workaround. Into the docker, in my home I create a directory, for example <project name>/node_modules. Them in my mapped directory within windows and linux(into the docker) I make a symbolic link within the directory I created before an “node_modules”. Something like ln -s <src> <dest> ln -s /home/my_project/node_modules /var/www/html/my_project/node_modules

Them, into my project I call the npm install

With this solution, the node-sass install with no problem.

I’m not an expert but I think the problem was the mapping within the windows and linux and the way that npm installs with links this package.

Best regards

I have the same error in the same environment (@METACEO : I guess you run docker on Windows ?), and indeed it seems to be related to how the directories in the container are mapped on the host. Maybe some magic with symlinks that the host FS doesn’t understand ? If I move package.json to another directory within the container that is not mapped on the host (say /tmp/), the npm install just goes fine.

It used to work quite recently so I guess some dependency changed its behavior in the meantime.

It seems there is no such problem with yarn, so I’ll temporarily switch away from npm.

I have exactly the same issue that I can reproduce as follow:

Context

Windows 10, WSL

$ uname -a
Linux nowox-pc 4.4.0-17134-Microsoft #471-Microsoft Fri Dec 07 20:04:00 PST 2018 
x86_64 x86_64 x86_64 GNU/Linux
$ docker --version
Docker version 18.09.1-beta1, build d3184b7

Minimal project

Only one package.json

$ tree
.
+-- package.json

0 directories, 1 file
$ cat package.json
{
  "devDependencies": {
    "node-sass": "^4.9.2"
  }
}

Failure on npm install

$ docker run -itv $(pwd -P):/app -w=/app node npm install

> node-sass@4.11.0 install /app/node_modules/node-sass
> node scripts/install.js

fs.js:121
    throw err;
    ^

Error: EINVAL: invalid argument, open '/app/node_modules/node-sass/package.json'
    at Object.openSync (fs.js:450:3)
    at Object.readFileSync (fs.js:350:35)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:738:20)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:657:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/app/node_modules/node-sass/lib/extensions.js:7:9)
    at Module._compile (internal/modules/cjs/loader.js:721:30)

I have added a .npmrc with rollback=false and I can confirm that package.json is readable:

$ docker run -itv $(pwd -P):/app -w=/app node head -n2 /app/node_modules/node-sass/package.json
{
  "_from": "node-sass@^4.9.2",

I had the extact issue yesterday. I have a windows 10 environment with docker running. I created an SPFX project using yeoman and after the scaffolding it gave out the same error.

I run the command yarn and it all went well.