markfinger / python-react

Server-side rendering of React components
MIT License
1.62k stars 116 forks source link

Having trouble with django integration #37

Closed krisfields closed 9 years ago

krisfields commented 9 years ago

The first time I try to render_component I get a BundlingError, and then subsequent attempts to render the same component result in a FunctionTimeout.

I followed all the instructions, first installing js-host and python-webpack (following each of their instructions), and then python-react but I am unable to get this to work with django. To avoid any possibility of it being something specific to the project I'm working on, I tried to get it working again in a fresh Django project but to no avail. I pushed that one to github in case it's helpful: https://github.com/krisfields/pythonreacttest

Could you take a look at the traceback below (and/or the github project) and see if you might be able to ascertain where I may have went wrong?

(pythonreacttest)Poor-Mans-Delegate:pythonreacttest avalaunchit$ python manage.py shell Connected to JSHostManager [127.0.0.1:9009] Connected to JSHost [127.0.0.1:49280] Python 2.7.6 (default, Sep 9 2014, 15:04:36) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole)

from react.render import render_component component = render_component('/Users/avalaunchit/Projects/personal/pythonreacttest/static/components/Comment.jsx', translate=True, props={}) Traceback (most recent call last): File "", line 1, in File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/react/render.py", line 105, in render_component bundled_component = bundle_component(path, translate=translate) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/react/bundle.py", line 31, in bundle_component return webpack(path_to_config_file) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/webpack/compiler.py", line 119, in webpack raise six.reraise(BundlingError, BundlingError(_e.args), sys.exc_info()[2]) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/webpack/compiler.py", line 116, in webpack bundleDir=settings.get_path_to_bundle_dir(), File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/function.py", line 35, in call res = self.send_request(__kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/function.py", line 92, in send_request res_text=res.text, BundlingError: webpack: EntryModuleNotFoundError: Entry module not found: Error: Cannot resolve module 'babel-loader' in /Users/avalaunchit/Projects/personal/pythonreacttest/static/components at Tapable. (/Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/lib/Compilation.js:350:28) at Tapable. (/Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/lib/NormalModuleFactory.js:84:21) at /Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:254:17 at done (/Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:129:15) at /Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:32:16 at /Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:251:21 at /Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:575:34 at /Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:254:17 at done (/Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:129:15) at /Users/avalaunchit/Projects/personal/pythonreacttest/node_modules/webpack/node_modules/async/lib/async.js:32:16 component = render_component('/Users/avalaunchit/Projects/personal/pythonreacttest/static/components/Comment.jsx', translate=True, props={}) Traceback (most recent call last): File "", line 1, in File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/react/render.py", line 105, in render_component bundled_component = bundle_component(path, translate=translate) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/react/bundle.py", line 31, in bundle_component return webpack(path_to_config_file) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/webpack/compiler.py", line 116, in webpack bundleDir=settings.get_path_to_bundle_dir(), File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/function.py", line 35, in call res = self.send_request(__kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/function.py", line 83, in send_request raise six.reraise(FunctionTimeout, FunctionTimeout(_e.args), sys.exc_info()[2]) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/function.py", line 78, in send_request timeout=timeout, File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/base_server.py", line 168, in send_json_request return self.send_request(_args, _kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/js_host.py", line 107, in send_request return super(JSHost, self).send_request(_args, _kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/js_host/base_server.py", line 159, in send_request return func(url, _kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/requests/api.py", line 109, in post return request('post', url, data=data, json=json, _kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/requests/api.py", line 50, in request response = session.request(method=method, url=url, _kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/requests/sessions.py", line 465, in request resp = self.send(prep, _send_kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/requests/sessions.py", line 573, in send r = adapter.send(request, **kwargs) File "/Users/avalaunchit/.virtualenvs/pythonreacttest/lib/python2.7/site-packages/requests/adapters.py", line 433, in send raise ReadTimeout(e, request=request) FunctionTimeout: HTTPConnectionPool(host='127.0.0.1', port=49280): Read timed out. (read timeout=10.0)

markfinger commented 9 years ago

Should be fixed now. The problem was in the JS lib, so you'll need to refer to https://github.com/markfinger/python-webpack/issues/19#issuecomment-102326983 for a diff that'll fix the problem

krisfields commented 9 years ago

Is babel-loader a required dependency? I was still getting the BundlingError until I installed it. Now it works great!

Thanks for the great package.

markfinger commented 9 years ago

Ah, good catch. Thanks for the heads up!