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

js-routes: Allow precompilation of routes.js file in development. #5232

Merged
merged 2 commits into from
Apr 29, 2021

Conversation

david-yz-liu
Copy link
Collaborator

@david-yz-liu david-yz-liu commented Apr 29, 2021

Motivation and Context

It looks like running MarkUs with Docker on WSL 2 runs into a webpacker compilation error:

Uncaught Error: Module build failed (from ./node_modules/rails-erb-loader/index.js):
Error: rails-erb-loader failed with code: 1
    at ChildProcess.<anonymous> (/app/node_modules/rails-erb-loader/index.js:128:16)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1022:16)
    at Socket.<anonymous> (internal/child_process.js:444:11)
    at Socket.emit (events.js:314:20)
    at Pipe.<anonymous> (net.js:675:12)
    erb application-b86bd25d2c8459646289.js:12001

I tried out various approaches in usabilityhub/rails-erb-loader#63 but didn't find one that worked (setting DISABLE_SPRING to 1, using bundle exec). When I inspect the webpack-dev-server output I see some permission errors associated with running rails, which rails-erb-loader does in a separate process.

webpacker_1  | Rails Error: Unable to access log file. Please ensure that /app/log/development.log exists and is writable (ie, make it writable for user and group: chmod 0664 /app/log/development.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
webpacker_1  | Traceback (most recent call last):
webpacker_1  |  60: from bin/rails:9:in `<main>'
...
webpacker_1  |   3: from /app/config/initializers/bullet.rb:6:in `<top (required)>'
webpacker_1  |   2: from /bundle/gems/bullet-6.1.4/lib/bullet.rb:128:in `bullet_logger='
webpacker_1  |   1: from /bundle/gems/bullet-6.1.4/lib/bullet.rb:128:in `open'
webpacker_1  | /bundle/gems/bullet-6.1.4/lib/bullet.rb:128:in `initialize': Permission denied @ rb_sysopen - /app/log/bullet.log (Errno::EACCES)

Your Changes

Description: I've introduced a workaround to precompile the js-routes file by doing rails js:routes, which generates app/javascript/routes.js. If present, this file will be imported by application.js instead of routes.js.erb.

Type of change (select all that apply):

  • Other (please specify): Development setup change

Testing

I verified that this allows webpacker to compile all of the required assets, so MarkUs can actually run!

Questions and Comments (if applicable)

I changed the extension .erb to .js.erb to allow webpacker to find routes.js.erb. We don't have any other assets that use the .erb extension (e.g., .css.erb), but if we ever do want that, we'll need to add them separately to the extensions list in webpacker.config. But I think it's best to limit our use of rails-erb-loader until we can figure out the root cause of this WSL issue.

Checklist

  • I have performed a self-review of my own code.
  • I have fixed any Hound bot comments.
  • I have verified that the TravisCI tests have passed.
  • I have reviewed the test coverage changes reported on Coveralls.
  • I have described any required documentation changes below.

Required documentation changes (if applicable)

I'm updating https://github.com/MarkUsProject/Markus/wiki/Developer-Guide--Set-Up-With-Docker to include setup instructions for WSL 2, and will include the js routes precompilation step for this platform.

david-yz-liu and others added 2 commits April 29, 2021 12:42
This is a workaround for an issue where rails-erb-loader fails to compile routes.js.erb
on the Windows Subsystem for Linux (version 2). I'm not sure what the root of the problem is.
This change is backwards compatible so it shouldn't affect running MarkUs on other platforms.
@mishaschwartz
Copy link
Contributor

Looks good. I just added the file to .dockerignore so that it won't be accidentally added to an image build

@david-yz-liu david-yz-liu merged commit 11207a7 into MarkUsProject:master Apr 29, 2021
@david-yz-liu david-yz-liu deleted the js-routes-wsl branch April 29, 2021 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants