添加 rails-erb-loader 会破坏 webpacker



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

我尝试过格式化包并以不同的方式导入文件,我尝试将包留空,我尝试删除所有包。我已经将问题缩小到默认的库存 Rails 部署,并安装了默认的 rails-erb-loader。轨道工作,添加 erb 加载器会破坏它。

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

--复制

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

我在使用erb加载器时也遇到了问题。在此评论中找到了解决方案。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,
},
}
}]
}

最新更新