在laradock上安装npm不能正常工作 [英] npm install on laradock not working

查看:166
本文介绍了在laradock上安装npm不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Laradock创建了一个Laravel项目.当我运行npm install时,得到以下输出.

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

基本上,它无法运行npm install命令.如果我在docker之外创建Laravel项目,它会完美工作.有人知道为什么吗?

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?

推荐答案

我也遇到了这个问题.我不知道何时引入此问题,因为我以前曾经能够在该项目上运行npm install,但是我总是有可能使用yarn install代替(这似乎可行).

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).

但是,我们正在尝试使用npm,所以我需要使它工作.

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

用于Windows github存储库的docker上有与此相关的问题.出现的问题是使用CIFS 3.02而不是CIFS 2.0装载卷时. Laradock正在对卷使用绑定安装,看起来它们默认为3.02.

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.

我不是Docker专家,所以也许有更好的方法可以解决此问题,但是我能够弄清楚如何使用CIFS 2.0更新docker-compose.yml以创建卷,并且解决了此问题.我.

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.

volumes:部分下,添加一个新卷.您可以命名任何东西,除了现有已定义卷之一.我叫我code.

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版本> = 7.0.0 :docker-compose.yml文件使用版本3,顶级volumes:部分在文件顶部附近定义.

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版本< 7 :docker-compose.yml文件使用版本2,顶层volumes:部分在文件底部定义.

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.

不幸的是,由于此卷定义在构建上下文之外,因此您将需要对代码的路径进行硬编码.您将无法使用APP_CODE_PATH_HOST变量(或< 7中的APPLICATION).

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).

您的volumes:部分将如下所示:

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"

您需要使用代码的路径更新device:选项,并且需要更新o:选项以填写用户名,密码和域.随时在.env文件中创建变量,并在此处使用它们.

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.

定义新卷后,您将需要更新workspace服务以使用新卷.

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

Laradock版本> = 7.0.0 :在workspace服务的volumes:部分中,将${APP_CODE_PATH_HOST}替换为新卷的名称(例如code).您的workspace音量定义如下:

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版本< 7 :在applications服务的volumes:部分中,将${APPLICATION}替换为新卷的名称(例如code).如果您的applications服务没有volumes:部分,请添加它.您的applications部分定义如下所示:

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

现在,当您打开容器并登录到workspace容器时,应使用CIFS 2.0装入卷.您可以通过运行mount | grep cifs进行验证,并在选项中看到它显示vers=2.0.

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的安装脚本现在应该能够找到package.json文件.假设您没有遇到其他任何错误,则npm install应该可以工作.

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.

这篇关于在laradock上安装npm不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆