question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Process is not defined

See original GitHub issue

I followed the tutorial and install the react-rails using these commands:

bundle install
rails g react:install

After that I created a component HelloMessage.jsx on /components folder:

var HelloMessage = React.createClass({
  render: function() {
    return (
      <h1>Hello {this.props.name}!</h1>
    )
  }
});

And when I render it:

<%= react_component('HelloMessage', name: 'John') %>

These errors are raised: image

Uncaught ReferenceError: process is not defined
    at index.self-a216c390bf956cbb906c66d29fdb2e2ad6999464a5ca83e476533a6f25ad0ef3.js?body=1:3
(anonymous) @ index.self-a216c390bf956cbb906c66d29fdb2e2ad6999464a5ca83e476533a6f25ad0ef3.js?body=1:3
HelloMessage.self-4549b24fbb2deaf10a4a0b39add3517999d4dfe318fedb65f157caa5c1ccf19c.js?body=1:1 Uncaught ReferenceError: React is not defined
    at HelloMessage.self-4549b24fbb2deaf10a4a0b39add3517999d4dfe318fedb65f157caa5c1ccf19c.js?body=1:1
(anonymous) @ HelloMessage.self-4549b24fbb2deaf10a4a0b39add3517999d4dfe318fedb65f157caa5c1ccf19c.js?body=1:1
react_ujs_mount.self-169a668bfd47eb081c36fa9e36ed23fa4d6088ff552a2065a64a571fc3c29837.js?body=1:83 [react-rails] Cannot find component: 'HelloMessage' for element <div data-react-class=​"HelloMessage" data-react-props=​"{"name":​"John"}​">​</div>​
react_ujs_mount.self-169a668bfd47eb081c36fa9e36ed23fa4d6088ff552a2065a64a571fc3c29837.js?body=1:84 Uncaught Error: Cannot find component: 'HelloMessage'. Make sure your component is globally available to render.
    at Object.mountComponents (react_ujs_mount.self-169a668bfd47eb081c36fa9e36ed23fa4d6088ff552a2065a64a571fc3c29837.js?body=1:84)
    at HTMLDocument.<anonymous> (react_ujs_turbolinks.self-19cb50a828b179c80e0ef6463ceb612ae3e75f377fb2dd6f4afdc3b46ae75d56.js?body=1:5)
    at Object.Turbolinks.dispatch (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
    at e.Turbolinks.Controller.e.notifyApplicationAfterPageLoad (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:7)
    at e.Turbolinks.Controller.e.pageLoaded (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:7)
    at turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
jacksontrieucommented, Feb 20, 2019

For anyone else who is having this issue, I found a fix which involved doing two things:

  1. If you have a app/assets/javascripts/server_rendering.js file, delete the whole file and make sure it isn’t referenced in a //= require statement in app/assets/javascripts/application.js

  2. Go to your app/assets/javascripts/application.js file and remove the following lines if they exist:

//= require react
//= require react_ujs

I think the reason why the error occurs is because my project was initially configured to run the react-rails gem in Asset Pipeline mode, whereby the first command I ran after installing the gem was:

rails g react:install

This adds those extra require statements in the app/assets/javascripts/server_rendering.js & app/assets/javascripts/application.js files, as it expects Rails’ asset pipeline to be bundling the react components.

Switching to Webpacker mode requires removing those require statements in those two files.

4reactions
BrunoQuaresmacommented, Mar 12, 2018

I removed the folder node_modules, ran again 'rails g react: install` and it worked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: “process is not defined” - GIMTEC
In this case, process is not defined in the browser environment, hence the error. The solution is to remove the reference to process...
Read more >
javascript - Uncaught ReferenceError: process is not defined
I am using the command "npm start" which refers to the "start" script inside package.json that is set to "start": "http-server -a localhost...
Read more >
"Uncaught ReferenceError: process is not defined" and the ...
The Uncaught ReferenceError: process is not defined happens when when a non-existent (here: process) variable is referenced .
Read more >
process is not defined (NOT react-error-overlay ... - GitHub
Using the optional chaining operator with process ( process?.env ) throws a ReferenceError stating that process is not defined.
Read more >
Uncaught ReferenceError: process is not defined : r/reactjs
Uncaught ReferenceError : process is not defined ... I'm getting this error and don't know how to fix it. ... These code snippets...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found