question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: ApiClient is not defined

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:28 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewRayCodecommented, May 1, 2016

@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.

1reaction
AndrewRayCodecommented, Apr 20, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

It's stuff like this, Javascript. : r/javascript - Reddit
MyApp = { api: new ApiClient(), store: store } // reducer.js console.log(MyApp) => Uncaught ReferenceError: MyApp is not defined.
Read more >
Uncaught Reference Error: gapi is not defined - Stack Overflow
The reason for that is that gapi is being set up asynchronously. In this case, listMajors() at the end of the script tag...
Read more >
ReferenceError: "x" is not defined - JavaScript - MDN Web Docs
The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.
Read more >
ipfs-http-client - npm
A client library for the IPFS HTTP API. Latest version: 59.0.0, last published: 2 months ago. Start using ipfs-http-client in your project ...
Read more >
Genesys Cloud Developer Forum
If I add this line to my code: import { ApiClient } from 'purecloud-… ... ReferenceError: You are trying to import a file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found