Limenius / ReactBundle

Client and Server-side React.js rendering in a Symfony Bundle
MIT License
390 stars 53 forks source link

TypeError: Cannot read property 'replace' of undefined #11

Closed imikay closed 8 years ago

imikay commented 8 years ago

An exception has been thrown during the rendering of a template ("Something went wrong evaluating JS code: result: "TypeError: Cannot read property 'replace' of undefined"")

Hi, do you had this error before? This error blocks me for two days, still don't know how to solve it, this is the only error message I got, no other information.

Maybe this is not a ReactBundle issue, but I don't know where else to ask.

Thanks.

nacmartin commented 8 years ago

That is an error produced when evaluating the JavaScript code on server side rendering. The problem is that when server side rendering the error trace is difficult to understand because it is referencing a temporary file without sourcemap.

To debug it you could set up only client side rendering and in the javascript console there should appear the same error, indicating the line where it is produced.

It could be something related to this bundle or something in your code, it is just indicating that there was an error found in the JavaScript part.

Also trace ({{ react_component('RecipesApp', {'props': props, 'trace': true}) }}) may help

imikay commented 8 years ago

Tried both, still no progress :confused: .

As long as I put {{ react_component('RecipesApp', {'props': props, 'trace': true}) }} in the template, this error will persist. My node version is v4.4.2 and npm is v2.15.0, I am going to drop this for a few days, then look into this problem again. The symfony-react-sandbox runs just fine though.

Thanks for the help.

nacmartin commented 8 years ago

Does it work adding the option 'rendering': 'client-side' ({'props': props, 'trace': true, 'rendering': 'client-side'})? That should run the code client-side and give a more helpful error message in the javascript console of Chrome dev inspector.

imikay commented 8 years ago

Oh, I misunderstood your meaning of rendering client before, just tried this, no erors in the console.

imikay commented 8 years ago

No generated React view on the page either, I checked the source and only say this on the page qq20160412-1

Maybe there's something wrong with my setting up process?

nacmartin commented 8 years ago

I think that it may be an error in your react code, that prevents the component from rendering. For some reason the component is not rendering. If I were you, I would try to rendering the component client-side without the bundle, in a normal fashion with only react, and see if it renders, or gives an error, or what.

Or, if you could publish in github the simplest case that reproduces this error, that I can Install and try, I can have a look at it.

nacmartin commented 8 years ago

I have pushed a new version just now (v0.8.4). Maybe it solves your problem, when rendering only client side as I saw that it was messing with the configuration when rendering only client side.

imikay commented 8 years ago

Thanks, I will update the bundle and try again. :+1:

imikay commented 8 years ago

There's a dependency issue:

Using version ^0.8.4 for limenius/react-bundle ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

Problem 1

  • The requested package nacmartin/phpexecjs == 0.8.4.0 is satisfiable by nacmartin/phpexecjs[v0.8.4] but those are rejected by your minimum-stability.

composer.json settings, and with minimum stability set to dev

    "limenius/react-bundle": "^0.8.4",
    "nacmartin/phpexecjs": "^0.8.5"
imikay commented 8 years ago

Delete and reinstall the bundle solved the dependency problem, sorry to bother.

imikay commented 8 years ago

I guess the problem is the lack of mounting code which mounts React module into the page, I am working in a hybrid environment, only part of the page is using React, I created a public repository here react-bundle-integrate, you can check it out.

Thanks for taking your valuable time for helping me, I'm really appreciated it.

nacmartin commented 8 years ago

Ok, I have been digging into this. It works with "react-on-rails": "^4.0.0" in package.json. Looks like with version 5 there is a problem rendering console messages inside that package (nothing very important, but annoying), or in the integration of this bundle with them. I will work in the next days into making this package compatible with version 5 or, if they have a bug, I'll try to report it to them.

For the moment, using version 4 should be fine, I think.

imikay commented 8 years ago

Yes, react-on-rails 4.0 works for me, thank you for your time and patience. :+1:

imikay commented 8 years ago

By the way, I think we should put the version requirement of the dependencies in the doc to prevent further problems like this. Thanks.