Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues using rails-erb-loader with yarn 2 #105

Open
jwoodrow opened this issue Nov 7, 2021 · 1 comment · May be fixed by #106
Open

Having issues using rails-erb-loader with yarn 2 #105

jwoodrow opened this issue Nov 7, 2021 · 1 comment · May be fixed by #106

Comments

@jwoodrow
Copy link

jwoodrow commented Nov 7, 2021

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'
    }
  }]
}
@jwoodrow jwoodrow changed the title Having issues using rails-era-loader with yarn 2 Having issues using rails-erb-loader with yarn 2 Nov 7, 2021
@jwoodrow
Copy link
Author

jwoodrow commented Nov 7, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant