laravel - npm 安装在 laradock 上不工作

标签 laravel docker npm npm-install laradock

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

> 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 项目,它会完美运行。有谁知道这是为什么吗?

最佳答案

我也遇到了这个问题。我不知道这个问题是什么时候引入的,因为我相信我以前可以在这个项目上运行 npm install,但我总是有可能使用 yarn install 相反(这似乎有效)。

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

docker for windows github repo 上有与此相关的问题.看来问题是使用 CIFS 3.02 而不是 CIFS 2.0 安装卷时。 Laradock 正在为卷使用绑定(bind)安装,看起来它们默认为 3.02。

我不是 docker 专家,所以可能有更好的方法来解决这个问题,但我能够弄清楚如何更新 docker-compose.yml 以使用创建卷CIFS 2.0,它为我解决了这个问题。

volumes: 部分下,添加一个新卷。您可以将其命名为任何名称,但现有定义的卷之一除外。我调用了我的 code

Laradock 版本 >= 7.0.0:docker-compose.yml 文件使用版本 3 和顶级 volumes: 部分在文件顶部附近定义。

Laradock 版本 <7:docker-compose.yml 文件使用版本 2,顶级 volumes: 部分定义在文件底部。

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

您的 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 文件中创建变量并在此处使用它们。

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

Laradock 版本 >= 7.0.0:在您的 workspace 服务的 volumes: 部分,替换 ${APP_CODE_PATH_HOST} 与您的新卷的名称(例如 code)。您的 workspace 卷定义如下所示:

      volumes:
        - code:${APP_CODE_PATH_CONTAINER}

Laradock 版本 < 7:在 volumes: 部分为您的 applications 服务,替换 ${APPLICATION} 使用新卷的名称(例如 code)。如果您的 applications 服务没有 volumes: 部分,请添加它。您的 applications 部分定义将如下所示:

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

现在,当您启动容器并登录到您的 workspace 容器时,您的卷应该使用 CIFS 2.0 安装。您可以通过运行 mount | 来验证grep cifs 并看到它在选项中显示 vers=2.0

node-sass 的安装脚本现在应该可以找到 package.json 文件了。假设您没有遇到任何其他错误,npm install 应该可以正常工作。

关于laravel - npm 安装在 laradock 上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50981002/

相关文章:

docker - 放置 Docker 应用程序使用的文件夹和文件的位置

php - 带有参数的 Laravel 4 mssql 存储过程作为准备好的语句

php - Laravel 5.4 结合两个集合

selenium - 如何在docker-compose.yml中配置Selenium Grid(最大 session 数)

npm - 有没有办法在不安装包的情况下按字母顺序排列 package.json ?

node.js - 在 typescript 中找不到 'autobind-decorator' 的声明文件

javascript - NPM:如何添加不为包消费者运行的 "post-install" Hook ?

php - Laravel 5 许多中间件和性能

php - Laravel - 如何连接来自不同数据库连接的 2 个表?

docker - Bluemix 安全网关 Docker 客户端的高可用性