Ad

Including Express In My React Project Gives Prototype Undefined Error

- 1 answer

I'm trying to setup a simple react project that will connect to a MySql database. I require 'express', rebuild and at that point I try pulling up the project in the browser and get the following error:

"Uncaught TypeError: Cannot read property 'prototype'of undefined"

I tried stripped everything out of my app.js file and tried include express all by itself. Same error.

When I tried HapiJs I get the same error, just on a different line of code in my main js file.

enter image description here

Ad

Answer

You can't require express or hapijs in react app. React is for frontend. Express is server, backend framework. You have to run express as server, and communicate your react app by ajax calls nExpress is server, backend framework. You have to run express as server, and communicate your react app by ajax calls with express api.

Edit: OP ask how he can create server app and client app and communicate them. This is very broad subject. I can't teach you this in one answer. You should study:

  1. how to create express server app with routes. (simple tutorial express + mongodb : http://adrianmejia.com/blog/2014/10/01/creating-a-restful-api-tutorial-with-nodejs-and-mongodb/)
  2. how to create react client app.
  3. how to run in server your react app
  4. hot to communicate react whit server api endpoints.

For 2. 3. 4. in this react tutorial they show how to create app and use jquery to ajax calls : https://facebook.github.io/react/docs/tutorial.html

Ad
source: stackoverflow.com
Ad