react-redux-universal-hot-example: ReferenceError: ApiClient is not defined
Hi,
I did a fresh install of react-rudex-universal-hot-example
on Node 0.12
# node -v
v0.12.5
# git clone git@github.com:erikras/react-redux-universal-hot-example.git
# cd react-redux-universal-hot-example
# npm install
# npm run dev
When I open localhost:3000
in my browser I get the following exception:
ReferenceError: ApiClient is not defined
[1] at new ApiClient (/home/rudolf/dev/react-redux-universal-hot-example/src/ApiClient.js:15:22)
[1] at /home/rudolf/dev/react-redux-universal-hot-example/src/server.js:39:16
[1] at Layer.handle [as handle_request] (/home/rudolf/dev/react-redux-universal-hot-example/node_modules/express/lib/router/layer.js:95:5)
[1] at trim_prefix (/home/rudolf/dev/react-redux-universal-hot-example/node_modules/express/lib/router/index.js:312:13)
...
I don’t know enough about babel
and ES6 to completely debug it. But I did manage to make it work by changing src/server.js:
diff --git a/src/server.js b/src/server.js
index 94c4b3a..507a812 100755
--- a/src/server.js
+++ b/src/server.js
@@ -36,7 +36,8 @@ app.use('/api', (req, res) => {
});
app.use((req, res) => {
- const client = new ApiClient(req);
+ let client = new ApiClient(req);
const redux = createRedux(client);
const location = new Location(req.path, req.query);
if (process.env.NODE_ENV === 'development') {
It doesn’t make sense how the scope of client
should change anything and as far as I can tell this produces the same compiled code.
Let me know if I can provide any more information?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 28 (16 by maintainers)
Commits related to this issue
- modified conditional devtools imports to pass eslint — committed to erikras/react-redux-universal-hot-example by deleted user 9 years ago
- split class definition and export to appease #14 — committed to erikras/react-redux-universal-hot-example by deleted user 9 years ago
- Mask ApiClient into a variable - #14 This, for reasons unknown at the time of this commit, allows us to avoid the mysterious "ReferenceError: ApiClient is not defined" error that appears the first ti... — committed to matthewryanscott/react-redux-universal-hot-example by matthewryanscott 9 years ago
- Mask ApiClient into a variable - #14 This, for reasons unknown at the time of this commit, allows us to avoid the mysterious "ReferenceError: ApiClient is not defined" error that appears the first ti... — committed to matthewryanscott/react-redux-universal-hot-example by matthewryanscott 9 years ago
- Mask ApiClient into a variable - #14 This, for reasons unknown at the time of this commit, allows us to avoid the mysterious "ReferenceError: ApiClient is not defined" error that appears the first ti... — committed to matthewryanscott/react-redux-universal-hot-example by matthewryanscott 9 years ago
- Fixing "_ApiClient is not defined" by bumping babel-core Fixes issue #14 #31 #51 Babel bug https://phabricator.babeljs.io/T2455 which is fixed and closed. I don't know which version of babel fixed i... — committed to AndrewRayCode/react-redux-universal-hot-example by AndrewRayCode 8 years ago
- Fixing "_ApiClient is not defined" by bumping babel-core Fixes issue #14 #31 #51 Babel bug https://phabricator.babeljs.io/T2455 which is fixed and closed. I don't know which version of babel fixed i... — committed to AndrewRayCode/react-redux-universal-hot-example by AndrewRayCode 8 years ago
- Fixing "_ApiClient is not defined" by bumping babel-core Fixes issue #14 #31 #51 Babel bug https://phabricator.babeljs.io/T2455 which is fixed and closed. I don't know which version of babel fixed i... — committed to AndrewRayCode/react-redux-universal-hot-example by AndrewRayCode 8 years ago
- Fixing "_ApiClient is not defined" by adding empty class method to ApiClient Fixes issue #14 #31 #51 Relevant Babel bug https://phabricator.babeljs.io/T2455 with more info. They claim it's v8. It ma... — committed to AndrewRayCode/react-redux-universal-hot-example by AndrewRayCode 8 years ago
- Fixing "_ApiClient is not defined" by adding empty class method to ApiClient Fixes issue #14 #31 #51 Relevant Babel bug https://phabricator.babeljs.io/T2455 with more info. They claim it's v8. It ma... — committed to Alexoner/react-redux-universal-hot-example by AndrewRayCode 8 years ago
@TruthReveller that doesn’t fix the bug, it just cases a server restart which masks it, and it can appear later. Please see the referenced PR for the current working workaround.
Edit: bumping babel does not fix this, sorry if you read the original comment.
After following the chain of tickets and comments and discussions this appears to be caused by the Babel bug T2455. Basically, exporting a class with only a constructor in older versions of babel sometimes failed.
The only reliable solution I can find is to add an empty class method to
ApiClient
. The babel devs claim it’s a v8 bug and have taken no further action.