Problem when I execute npm install on docker

假装没事ソ 提交于 2019-11-29 04:48:45

npm install is falling while installing node-sass. I have faced this issue personally many times and npm rebuild node-sass command always helps me out.

Hope, it does for you too :)

Since it fails on readFileSync/openSync, this can be related to file synchronization issues between Docker and your host (Windows). It fails in /var/www which is most likely the folder which you're sharing as a volume inside the Docker container.

As for the workaround, you can exclude a node_modules sub-folder and make it persistent.

If you're using docker-compose.yml, mount a persistent docker volume in place of your local node_modules directory, e.g.

...
  volumes:
    - .:/var/www
    - node_modules:/var/www/node_modules

See: Add a volume to Docker, but exclude a sub-folder

Related GitHub issue: EINVAL: invalid argument, open 'node-sass/package.json'.

Check also node-sass's troubleshooting page.

Related question: npm install on laradock not working.

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:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!