npm install on laradock not working

半腔热情 提交于 2019-12-07 14:20:09

问题


I created a Laravel project using Laradock. When I run npm install I get the following output.

> node-sass@4.9.0 install /var/www/npmtest/node_modules/node-sass
> node scripts/install.js

fs.js:119
    throw err;
    ^

Error: EINVAL: invalid argument, open '/var/www/npmtest/node_modules/node-sass/package.json'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:348:35)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:719:20)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/var/www/npmtest/node_modules/node-sass/lib/extensions.js:7:9)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
npm WARN rollback Rolling back is-fullwidth-code-point@1.0.0 failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/gauge/node_modules/is-fullwidth-code-point'
npm WARN rollback Rolling back is-fullwidth-code-point@1.0.0 failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/sass-graph/node_modules/is-fullwidth-code-point'
npm WARN rollback Rolling back chalk@1.1.3 failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/node-sass/node_modules/chalk'
npm WARN rollback Rolling back string-width@1.0.2 failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/gauge/node_modules/string-width'
npm WARN rollback Rolling back chalk@1.1.3 failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/har-validator/node_modules/chalk'
npm WARN rollback Rolling back assert-plus@1.0.0 failed (this is probably 

..... ..... .....

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.9.0 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.9.0 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-06-22T04_51_41_566Z-debug.log

basically it fails to run the npm install command. It works perfectly if I create Laravel projects outside docker. Does anyone know why this is?


回答1:


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.




回答2:


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 :)!




回答3:


Try to rebuild workspace container:

docker-compose build workspace


来源:https://stackoverflow.com/questions/50981002/npm-install-on-laradock-not-working

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