添加rails-erb-loader会破坏webpacker

时间:2019-09-15 09:09:52

标签: ruby-on-rails webpack erb

我正在尝试启动并运行基本的Rails部署(rails新项目名称--webpack)。一切正常,rake webpacker:compile正常。但是,一旦添加了rails-erb-loader(rails webpacker:install:erb),它就会中断编译过程。如果webpacker开始编译,它只会冻结在“ compiling ..”,并且永远不会结束。这可能会持续数小时,但没有结果,直到我终止该过程。没有错误消息。

我尝试以不同的方式格式化数据包和导入的文件,我尝试将数据包留空,我尝试删除所有数据包点为空白。我将问题缩减为默认的默认Rails部署,并安装了默认的rails-erb-loader。 Rails可以正常工作,添加erb加载程序会破坏它。

已经从webpacker文件夹中的文件中删除了所有注释(因为这些注释将由ERB解释)。我也将文件扩展名更改为.js.erb。 这是三天前的工作,我不知道我现在在做什么错。

-复制

(Enter into bash)
rails new project-name --webpack
cd project-name
rake webpacker:compile (will work)
rails webpacker:install:erb
rake webpacker:compile (will hang)

-控制台输出((--trace在“编译..”之后将不返回任何输出)

rake webpacker:compile
Compiling…
^C#<Thread:0x00007fffc66119f8@/usr/share/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/open3.rb:287 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        1: from /usr/share/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/open3.rb:287:in `block (2 levels) in capture3'
/usr/share/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/open3.rb:287:in `read': stream closed in another thread (IOError)
#<Thread:0x00007fffc66118b8@/usr/share/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/open3.rb:288 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        1: from /usr/share/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/open3.rb:288:in `block (2 levels) in capture3'
/usr/share/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/open3.rb:288:in `read': stream closed in another thread (IOError)
rake aborted!
Interrupt:
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/webpacker/compiler.rb:61:in `run_webpack'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/webpacker/compiler.rb:21:in `compile'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/webpacker/commands.rb:18:in `compile'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/webpacker.rb:27:in `compile'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/tasks/webpacker/compile.rake:31:in `block (4 levels) in <main>'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/tasks/webpacker/compile.rake:6:in `ensure_log_goes_to_stdout'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/tasks/webpacker/compile.rake:30:in `block (3 levels) in <main>'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/webpacker.rb:20:in `with_node_env'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/webpacker-4.0.7/lib/tasks/webpacker/compile.rake:29:in `block (2 levels) in <main>'
/home/melvin/.rvm/gems/ruby-2.6.3/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/home/melvin/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
/home/melvin/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => webpacker:compile
(See full trace by running task with --trace)

1 个答案:

答案 0 :(得分:0)

我也遇到了erb-loader问题。在此评论中找到了解决方案。 erb加载器和弹簧相互作用存在一些问题,这会导致冻结。要修复它,只需添加

env:        {
    ...process.env,
    DISABLE_SPRING: 1,
  }

到erb-loader config(config / webpack / loaders / erb.js)中的选项,因此整个配置如下所示:

module.exports = {
  test: /\.erb$/,
  enforce: 'pre',
  exclude: /node_modules/,
  use: [{
    loader: 'rails-erb-loader',
    options: {
      runner: (/^win/.test(process.platform) ? 'ruby ' : '') + 'bin/rails runner',
      env:        {
        ...process.env,
        DISABLE_SPRING: 1,
      },
    }
  }]
}