React-rails: Can't resolve react_ujs

Created on 18 May 2017  路  3Comments  路  Source: reactjs/react-rails

Help us help you! Please choose one:

  • [x] My app crashes with react-rails, so I've included the stack trace and the exact steps which make it crash.
  • [ ] My app doesn't crash, but I'm getting unexpected behavior. So, I've described the unexpected behavior and suggested a new behavior.
  • [ ] I'm trying to use react-rails with another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working.

    - [ ] I have another issue to discuss.

I followed the steps described in the readme to setup react via webpacker, but when I run ./bin/webpack-dev-server I got the following compile error:

ERROR in ./app/javascript/packs/server_rendering.js
Module not found: Error: Can't resolve 'react_ujs' in '/Users/chrisarmstrong/Projects/debate_platform/app/javascript/packs'
 @ ./app/javascript/packs/server_rendering.js 4:20-40
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./app/javascript/packs/server_rendering.js

ERROR in ./app/javascript/packs/application.js
Module not found: Error: Can't resolve 'react_ujs' in '/Users/chrisarmstrong/Projects/debate_platform/app/javascript/packs'
 @ ./app/javascript/packs/application.js 13:20-40
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./app/javascript/packs/application.js

Here are the contents of the two files in question:

packs/application.js
```console.log('Hello World from Webpacker')
// Support component names relative to this directory:
var componentRequireContext = require.context("components", true)
var ReactRailsUJS = require("react_ujs")
ReactRailsUJS.useContext(componentRequireContext)

`packs/server_rendering.js`
```var componentRequireContext = require.context("components", true)
var ReactRailsUJS = require("react_ujs")
ReactRailsUJS.useContext(componentRequireContext)

Most helpful comment

The install generator _should_ do this for you, but can you try installing react_ujs with yarn?

yarn add react_ujs

?

Then, restart webpack-dev-server and try again?

All 3 comments

The install generator _should_ do this for you, but can you try installing react_ujs with yarn?

yarn add react_ujs

?

Then, restart webpack-dev-server and try again?

@rmosolgo that worked, thanks! Not sure why the generator didn't work...

@chrismv48 - I had similar issue, check #716.

I guess we'll have to wait until @rmosolgo releases updated gem.
Until then gem 'react-rails', git: 'https://github.com/react/react-rails' should also help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scottbarrow picture scottbarrow  路  5Comments

prasanthrubyist picture prasanthrubyist  路  3Comments

kyleknighted picture kyleknighted  路  5Comments

wenwei63029869 picture wenwei63029869  路  3Comments

davidlormor picture davidlormor  路  3Comments