gpt4 book ai didi

ruby-on-rails - 添加 rails-erb-loader 会破坏 webpacker

转载 作者:行者123 更新时间:2023-12-04 15:40:42 27 4
gpt4 key购买 nike

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

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

已经从 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-loader 的问题。在此评论中找到解决方案。 erb-loader 和 spring 交互存在一些问题导致卡住。要修复它,只需要添加

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

到 erb-loader 配置(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,
},
}
}]
}

关于ruby-on-rails - 添加 rails-erb-loader 会破坏 webpacker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57942674/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com