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

Created on 23 Oct 2018  路  18Comments  路  Source: sass/node-sass

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
[email protected] /code
`-- @angular-devkit/[email protected]
  `-- UNMET DEPENDENCY [email protected]

npm ERR! missing: [email protected], required by @angular-devkit/[email protected]

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)

> [email protected] install /code/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0

> [email protected] 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! [email protected] install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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#

Most helpful comment

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?

All 18 comments

(Possibly related to #2515 submitted a few days ago.)

2 things pop out, but might not be related.

  1. Your running as root, and root has issues with NPM https://github.com/sass/node-sass/blob/master/TROUBLESHOOTING.md#linux
  2. Not a Docker expert, but there might be something off with your workspace mappings that's preventing the install from writing to the mapped partition.

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.

@gwenl yea, docker on windows, I haven't yet had the time to answer @nschonni questions, but I was wanting to try exactly what you suggested (relocating out of a mapped directory and installing the project there.) I'll try yarn as well.

I am seeing this with another project of mine (something that does not have node-sass as a dependency.) @gwenl I tried what you suggested and copied my project to another folder within my container and I no longer encounter any errors. This looks to be a windows <-> docker issue regarding mounted volumes. @nschonni - I believe it is safe to close this issue as it looks to be unrelated of node-sass.

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.

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.

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 /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
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 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

> [email protected] 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",

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.

Hi @METACEO ,

This solution works for me. But when we run "npm run watch" for compiling js / css not work.
Do you have a solution for it? Thanks in advance.

@nahdonivr - I don't know what exactly your watch script is doing, but my team is running ng serve which also watches for changes in ts/scss/html and it has been working fine. Curious, what errors are you getting?

@METACEO watch script ("npm run watch") runs command repeatedly and watches the js/css changes and output. I am using Laravel 5.6 and React 16. No errors gives but it does not watch the changes in local js/css.

The solution you have given solves the error "Error: EINVAL: invalid argument, open '/code/node_modules/node-sass/package.json".

I am using docker on window 10, installed same version of node in my docker container.

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?

Confirming same problem. Win10, Docker Alpine (and have tried Ubuntu), Node 10.13.0. node-sass just will not install regardless of global, local, nothing.

I had the same error. Using yarn instead of npm helped.

But after running this command it has also been working with npm:

npm install --save-dev --unsafe-perm node-sass

Found this answer on Stackoverflow

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?

Source: @shawmanz32na's comment

@shawmanz32na were you able to find related issues in the respective repositories?

Just got bit by this today, and am hoping to actually track the appropriate issue(s).

@virtuoushub Nope, no news here. I'm still hoping for a response from someone on this project, perhaps @nschonni.

I'm closing this thread as it isn't an issue with node-sass, and there have been solutions above to general SO answers on this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

primiano picture primiano  路  3Comments

Pixelatex picture Pixelatex  路  3Comments

harukaeru picture harukaeru  路  3Comments

samayo picture samayo  路  3Comments

bgolubovic picture bgolubovic  路  3Comments