npm install on laradock not working

偶尔善良 提交于 2019-12-06 04:07:23

I ran into this issue as well. I don't know when the issue was introduced, as I believe I used to be able to run npm install on this project before, but it's always possible I was using yarn install instead (which seems to work).

However, we're trying to use npm, so I needed to get that working.

There is an issue related to this on the docker for windows github repo. It appears the issue is when the volume is mounted using CIFS 3.02 instead of CIFS 2.0. Laradock is using bind mounts for the volumes, which looks like they default to 3.02.

I am not a docker expert, so there may be a better way to go about this, but I was able to figure out how to update the docker-compose.yml to create a volume using CIFS 2.0, and it resolved this issue for me.

Under the volumes: section, add a new volume. You can name it anything, except one of the existing defined volumes. I called mine code.

Laradock version >= 7.0.0: the docker-compose.yml file uses version 3 and the top-level volumes: section is defined near the top of the file.

Laradock version < 7: the docker-compose.yml file uses version 2 and the top-level volumes: section is defined at the bottom of the file.

Unfortunately, since this volume definition is outside of the build contexts, you will need to hard code the path to your code; you won't be able to use the APP_CODE_PATH_HOST variable (or APPLICATION in < 7).

Your volumes: section will look like this:

volumes:
  mysql:
    driver: ${VOLUMES_DRIVER} (or "local")
  percona:
    driver: ${VOLUMES_DRIVER} (or "local")
  [other volumes removed for brevity...]
  code:
    driver: "local"
    driver_opts:
      type: cifs
      device: //10.0.75.1/C/path/to/your/code/
      o: "rw,relatime,vers=2.0,sec=ntlmsspi,cache=strict,username=[your user name],password=[your password],domain=[your domain, if any; otherwise remove this],uid=0,noforceuid,gid=0,noforcegid,addr=10.0.75.1,file_mode=0755,dir_mode=0755,iocharset=utf8,nounix,serverino,mapposix,nobrl,mfsymlinks,noperm,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1"

You'll need to update the device: option with the path to your code, and you'll need to update the o: option to fill in your username, password, and domain. Feel free to create variables in your .env file and use those in here.

Once your new volume is defined, you will need to update your workspace service to use the new volume.

Laradock version >= 7.0.0: In the volumes: section for your workspace service, replace ${APP_CODE_PATH_HOST} with the name of your new volume (e.g. code). Your workspace volume definition will look like:

      volumes:
        - code:${APP_CODE_PATH_CONTAINER}

Laradock version < 7: In the volumes: section for your applications service, replace ${APPLICATION} with the name of your new volume (e.g. code). If your applications service doesn't have a volumes: section, add it. Your applications section definition will look like:

      applications:
        image: tianon/true
        volumes:
          - code:/var/www

Now when you bring up your containers and log into your workspace container, your volume should be mounted using CIFS 2.0. You can verify by running mount | grep cifs and see that it says vers=2.0 in the options.

node-sass's install script should be able to find the package.json file now. Assuming you don't run into any other errors, npm install should work.

I was also running in to the same problem with laradock, although i don't have a solution for using NPM. It should work using yarn install I don't have enough knowledge to know why this occurs but I hope it helps :)!

Andrew Boyko

Try to rebuild workspace container:

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