ruby-on-rails - Webpacker 编译失败 - 错误 : [Errno 21] Is a directory: 'bin'

标签 ruby-on-rails ruby docker ruby-on-rails-6 webpacker

我刚开始尝试使用 Docker,一切都在顺利进行,直到我尝试访问我的 super 基本应用程序的页面。我明白了:

web_1    | [Webpacker] Compiling...
web_1    | [Webpacker] Compilation failed:
web_1    | ERROR: [Errno 21] Is a directory: 'bin'
web_1    | CRITICAL:root:Traceback (most recent call last):
web_1    |   File "/usr/lib/python2.7/dist-packages/cliapp/app.py", line 182, in _run
web_1    |     self.settings.load_configs()
web_1    |   File "/usr/lib/python2.7/dist-packages/cliapp/settings.py", line 829, in load_configs
web_1    |     self._read_ini(pathname, f)
web_1    |   File "/usr/lib/python2.7/dist-packages/cliapp/settings.py", line 838, in _read_ini
web_1    |     cp.readfp(f)
web_1    |   File "/usr/lib/python2.7/ConfigParser.py", line 324, in readfp
web_1    |     self._read(fp, filename)
web_1    |   File "/usr/lib/python2.7/ConfigParser.py", line 512, in _read
web_1    |     raise MissingSectionHeaderError(fpname, lineno, line)
web_1    | MissingSectionHeaderError: File contains no section headers.
web_1    | file: /usr/src/app/config/webpack/development.js, line: 1
web_1    | "process.env.NODE_ENV = process.env.NODE_ENV || 'development'\n"
web_1    | 
web_1    | Traceback (most recent call last):
web_1    |   File "/usr/lib/python2.7/dist-packages/cliapp/app.py", line 182, in _run
web_1    |     self.settings.load_configs()
web_1    |   File "/usr/lib/python2.7/dist-packages/cliapp/settings.py", line 829, in load_configs
web_1    |     self._read_ini(pathname, f)
web_1    |   File "/usr/lib/python2.7/dist-packages/cliapp/settings.py", line 838, in _read_ini
web_1    |     cp.readfp(f)
web_1    |   File "/usr/lib/python2.7/ConfigParser.py", line 324, in readfp
web_1    |     self._read(fp, filename)
web_1    |   File "/usr/lib/python2.7/ConfigParser.py", line 512, in _read
web_1    |     raise MissingSectionHeaderError(fpname, lineno, line)
web_1    | MissingSectionHeaderError: File contains no section headers.
web_1    | file: /usr/src/app/config/webpack/development.js, line: 1
web_1    | "process.env.NODE_ENV = process.env.NODE_ENV || 'development'\n"

这是我第一次看到这个错误。

这是我的 docker-compose.yml

version: '3'                                                                                                                                                                                                                          

services:

  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/usr/src/app

这是我的 Dockerfile:

FROM ruby:2.6                                                                                                                                                                                                                         

LABEL maintainer="ejvalmores@gmail.com"

RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
nodejs

RUN apt-get install -yqq yarn

COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
RUN bundle install

COPY . /usr/src/app

CMD ["bin/rails", "s", "-b", "0.0.0.0"]

这是我的 Gemfile:

source 'https://rubygems.org'                                                                                                                                                                                                         
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.5'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.2', '>= 6.0.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'redis'

有人遇到过这个错误吗?请帮忙。谢谢!

最佳答案

我遇到了同样的错误。也许你需要安装最新版本的 nodejs 和 yarn。

将此添加到您的 Dockerfile:

(假设你有curl,如果没有安装)

RUN curl -sL https://deb.nodesource.com/setup_12.x  | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y nodejs yarn

然后在最后添加以下内容进行编译:

RUN npm rebuild node-sass #maybe you don't need it, I do
RUN bundle exec rails assets:precompile

也是我找到大部分信息的来源:https://github.com/yarnpkg/yarn/issues/7329

关于ruby-on-rails - Webpacker 编译失败 - 错误 : [Errno 21] Is a directory: 'bin' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60908878/

相关文章:

javascript - 在 javascript 中渲染 html.erb 模板

ruby-on-rails - 运行 "db:test:load => db:test:purge"而不重置数据库

ruby-on-rails - 无法将Tyre(和ElasticSearch)的混合 boolean 值混合在一起

用 "*"替换每个字符\d 的 Ruby 单行正则表达式?

ruby-on-rails - Rspec Ruby on Rails Controller 问题

oracle - 为什么 oracle 连接在 mac os sierra 上打开这么慢?

laravel - 在有作业运行时如何将laravel部署到Docker容器中

ruby-on-rails - 用于创建方法 smart_listing 的 Rails 嵌套路由

ruby-on-rails - rails 中的面包屑

maven - Jenkins Pipeline-无法连接到Docker守护程序