erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12k stars 2.5k forks source link

ReferenceError: _ApiClient is not defined #965

Open mahavira opened 8 years ago

mahavira commented 8 years ago

[1] ReferenceError: _ApiClient is not defined [1] at new _ApiClient (ApiClient.js:22:7) [1] at server.js:68:18 [1] at Layer.handle [as handle_request] (/Users/linmingxiong/www/examples/react-redux-universal-hot-example/node_modules/express/lib/router/layer.js:95:5) [1] at trim_prefix (/Users/linmingxiong/www/examples/react-redux-universal-hot-example/node_modules/express/lib/router/index.js:312:13) [1] at /Users/linmingxiong/www/examples/react-redux-universal-hot-example/node_modules/express/lib/router/index.js:280:7 [1] at Function.process_params (/Users/linmingxiong/www/examples/react-redux-universal-hot-example/node_modules/express/lib/router/index.js:330:12) [1] at next (/Users/linmingxiong/www/examples/react-redux-universal-hot-example/node_modules/express/lib/router/index.js:271:10) [1] at SendStream.error (/Users/linmingxiong/www/examples/react-redux-universal-hot-example/node_modules/serve-static/index.js:120:7) [1] at emitOne (events.js:77:13) [1] at SendStream.emit (events.js:169:7)

t0x1c123 commented 8 years ago

Same here...

tearsofphoenix commented 8 years ago

See #931 & #14 . To me it's some bug with cache & webpack-assets.json. @mahavira @t0x1c123

t0x1c123 commented 8 years ago

I fixed it by editing ApiClient.js to this -> `import superagent from 'superagent'; import config from '../config';

const methods = ['get', 'post', 'put', 'patch', 'del'];

export default class ApiClient { formatUrl(path) { const adjustedPath = path[0] !== '/' ? '/' + path : path; if (SERVER) { // Prepend host and port of the API server to the path. return ${config.useSsl ? 'https' : 'http'}:// + 'localhost:3030/api' + adjustedPath; } // Prepend /api to relative URL, to proxy to API server. return '/api' + adjustedPath; }

constructor(req) { methods.forEach((method) => this[method] = (path, {params, data} = {}) => new Promise((resolve, reject) => { const request = superagentmethod; if (params) { request.query(params); } if (SERVER && req.get('cookie')) { request.set('cookie', req.get('cookie')); } if (data) { request.send(data); } request.end((err, {body} = {}) => err ? reject(body || err) : resolve(body)); })); } }

export function formatUrl(path) { const adjustedPath = path[0] !== '/' ? '/' + path : path; if (SERVER) { // Prepend host and port of the API server to the path. return ${config.useSsl ? 'https' : 'http'}:// + 'localhost:3030/api' + adjustedPath; } // Prepend /api to relative URL, to proxy to API server. return '/api' + adjustedPath; }

`

tfitos commented 8 years ago

I had this ReferenceError: _ApiClient is not defined problem on node v5.0.0, then upgraded to v5.6.0 and now everything is fine.

AndrewRayCode commented 8 years ago

I got this error once on app startup, then restarting the dev server removed it. No idea why, but I wasn't changing any library/node versions, just restarted the server. A caching bug as initially mentioned sounds like a likely culprit.

gihrig commented 8 years ago

Similar experience to @DelvarWorld, only I had to reboot my Mac (10.10.5). Restarting server (npm run dev) didn't solve it for me. Been fine since.

Doubl3 commented 8 years ago

I've tested this project example yesterday using Node v5.1.0 (npm v3.3.12): either the "prod" and the "dev" runtime failed on error (with 2 different kind of errors, including the ApiClient one for the "prod" runtime). Today i've upgraded my Node version to v5.7.1 (npm v3.6.0) and no more error appear both for "prod" & "dev" runtime.

Each test was made after a fresh installation : rimraf the cloned dir -> git clone this repo -> npm install -> npm start OR npm run dev.

Hope it will help the community use this well tailored-made starter kit, though I can't figure out what's the root cause of these errors.

oriolpuig commented 8 years ago

I have experienced the same problem and I solve restarting the server. It's strange but... works fine!

tearsofphoenix commented 8 years ago
  1. upgrade npm & node;
  2. delete cache files. (such as webpack-assets.json);
  3. clear browser cache or disable it, if you have former webapp on port 3000 with appcache, it maybe the reason;
  4. restart the computer;
  5. change to export default class ApiClient in helpers/ApiClient.js;
  6. disable Server Side Rendering. (I don't think it matters, but sometimes it works)
ghost commented 8 years ago

I ran into the stated issue upon first run. After nvm install v5.6 && nvm use v5.6 and rebuilding my sass bindings with npm rebuild node-sass I was able to get a clean build.

NathanBWaters commented 8 years ago

Also had this problem when running npm run dev for the first time. Worked well once I ran npm run dev for the second time. Didn't change anything.

tearsofphoenix commented 8 years ago

Strange! The error has occurred sometimes, then it gone with the wind. The Environment is the reason.

quicksnap commented 8 years ago

oh no.. it's back.. @erikras do you happen to have more insight, or remember who ended up tracking this down?

I think this has to do with which node version is being used at runtime?

quicksnap commented 8 years ago

I'm open to PRs that can track down and fix this problem. Someone may want to try bisecting the error.. I know this issue was addressed in the past.

Doubl3 commented 8 years ago

I didn't experience the APIClient issue again (after having upgrading my Node & NPM to v5.7.1+) but I assume this PR should definitely solve the pb : #1113 (no more _ApiClient private ref required).