【问题标题】:Node/Docker is node-sass not finding installed bindings (via Webpack)Node/Docker 是 node-sass 找不到已安装的绑定(通过 Webpack)
【发布时间】:2018-08-14 18:55:56
【问题描述】:

我正在努力在基于 node:latest 的 docker 容器中设置 webpack 开发服务器

尽管尝试了Node Sass could not find a binding for your current environment 中的所有各种咒语,我仍然收到相同的错误:

web_1         | ERROR in ./~/css-loader!./~/sass-loader/lib/loader.js!./src/sass/style.sass
web_1         | Module build failed: Error: Missing binding /prject/node_modules/node-sass/vendor/linux-x64-59/binding.node
web_1         | Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 9.x
web

这是当前的

# Dockerfile
RUN yarn cache clean && yarn install --non-interactive --force
RUN rm -rf node_modules/node_sass
RUN npm rebuild node-sass

重建步骤表明二进制文件安装并检出:

Binary found at /advocate/node_modules/node-sass/vendor/linux-x64-59/binding.node
Testing binary
Binary is fine

让我感到困惑的是我确实得到了这个

web_1         | Found bindings for the following environments:
web_1         |   - OS X 64-bit with Node.js 7.x

这让我觉得它以某种我不太理解的能力使用主机平台。

【问题讨论】:

  • 尝试将node_modules 添加到您的.dockerignore 文件中。安装将需要更长的时间,但您不应在开发环境和容器之间进行任何交叉。
  • 我这样做了,它工作了大约 12 个小时,但现在又出现了同样的错误(无疑是由于我在此期间做了某事).. . 是否有可能docker-compose 卷条目是罪魁祸首? - ../code-frontend/:/code/ ... 初始测试(注释掉所述行并重建)建议如此

标签: node.js docker webpack-dev-server node-sass webpack-style-loader


【解决方案1】:

node_modules 目录的状态正在从开发主机转移到容器中。当在npm/yarn install(通常是使用本机代码的模块)期间做出基于平台的决策时,这是一个问题。

Dockerfile 构建

node_modules 添加到您的.dockerignore 文件中。在容器中安装将花费更长的时间,但您永远不应该在您的开发环境和容器之间进行任何交叉。

安装开发量

将带有node_modules 的开发代码安装到容器中也会导致同样的问题。在使用之前在新平台上运行yarn install --force 通常应该足以将其切换/返回。

在挂载卷时,没有一种简单的方法可以忽略目录。您可以单独挂载项目中的每个目录/文件,然后忽略node_modules,但这是很多工作。

同步开发量

这是一种避免安装卷的方法。 docker-sync 有一个 rsync strategy 可以忽略文件。这也可能会加快某些具有大量文件访问模式的应用程序的速度。从 osx > vm > docker 挂载的卷上的文件访问速度很慢。

version: '2'

options:
  verbose: true

syncs:
  yourproject_data:
    sync_strategy: 'rsync'
    src: './'
    sync_host_port: 10872
    sync_args: '-v' 
    sync_excludes:
      - '.sass-cache/'
      - 'sass-cache/'
      - 'vendor/'
      - 'bower_components/'
      - 'node_modules/'
      - '.git/'

默认情况下,文件删除不会同步到容器,您需要考虑这一点。当我需要清理时,我会偶尔删除同步的卷。

【讨论】:

    【解决方案2】:

    试试这个命令:

    sudo npm -g config 设置用户root

    我也有同样的问题。通过将 npm 用户设置为 root 用户来修复。

    【讨论】:

      猜你喜欢
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-07-04
      • 1970-01-01
      • 2017-04-12
      • 2016-10-25
      • 2020-05-27
      • 2019-12-12
      相关资源
      最近更新 更多