usabilityhub/rails-erb-loader

Having issues using rails-erb-loader with yarn 2

Opened this issue · 1 comments

Hi,

I'm trying to migrate an existing project from yarn to yarn 2 (with pnp) but I'm encountering a strange issue when it comes to rails-erb-loader and webpack/webpacker

I'm using rails-erb-loader for a single file in webpacker which is i18njs translations (and a few extras) basically

But when I run bin/webpack-dev-server locally, after migrating to yarn 2 and dealing with the issues that pnp would raise, I get an error when trying to compile my i18njs/index.erb file which makes me think there's an issue with the way the runner is executed.

Please specify a valid ruby command or the path of a script to run.
Run 'rails runner -h' for help.

/Users/jwoodrow/.rvm/gems/ruby-3.0.1/gems/railties-6.1.4.1/lib/rails/commands/runner/runner_command.rb:45: unknown regexp options - jwdrw
/Users/jwoodrow/Work/project/.yarn/__vi...
      ^~~~~~~~~
/Users/jwoodrow/.rvm/gems/ruby-3.0.1/gems/railties-6.1.4.1/lib/rails/commands/runner/runner_command.rb:45: syntax error, unexpected '.'
...rs/jwoodrow/Work/project/.yarn/__virtual__/rails-erb-lo...
...                              ^
/Users/jwoodrow/.rvm/gems/ruby-3.0.1/gems/railties-6.1.4.1/lib/rails/commands/runner/runner_command.rb:45: syntax error, unexpected local variable or method, expecting end-of-input
...s-erb-loader-virtual-84e156f2b7/0/cache/rails-erb-loader-npm...

Is there something I'm not understanding here ? Everything works fine as long as I'm not using pnp by the way

The loader config is this one

{
  test: /\.erb$/,
  enforce: 'pre',
  exclude: /node_modules/,
  use: [{
    loader: 'rails-erb-loader',
    options: {
      runner: 'bundle exec rails runner'
    }
  }]
}

Just a head's up to let you know that changing this (in the transformSource method) worked.

var child = spawn(
  runner.file,
  runner.arguments.concat(
    runnerPath,
    ioDelimiter,
    config.engine
  ),
  subprocessOptions
)

to

var child = spawn(
  runner.file,
  runner.arguments.concat(
    `"${runnerPath}"`,
    ioDelimiter,
    config.engine
  ),
  subprocessOptions
)

I think the runner interprets the absolute path as a regex because of the initial / and that breaks everything