Help us help you! Please choose one:
react-rails, so I've included the stack trace and the exact steps which make it crash.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 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)
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.
Most helpful comment
The install generator _should_ do this for you, but can you try installing
react_ujswithyarn??
Then, restart webpack-dev-server and try again?