Skip to content

Instantly share code, notes, and snippets.

@appsforartists
Created September 10, 2014 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appsforartists/0870a67838b580e75b27 to your computer and use it in GitHub Desktop.
Save appsforartists/0870a67838b580e75b27 to your computer and use it in GitHub Desktop.
Bug in DefinePlugin?
// …
// SERVER_IP is defined in Webpack, since the client can't run my-local-ip
"API_BASE_URL": "http://" + (require("my-local-ip")() || SERVER_IP) + ":8082/",
// …
/* this is being exported from webpack as:
// SERVER_IP is defined in Webpack, since the client can't run my-local-ip
"API_BASE_URL": "http://" + (__webpack_require__(197)() || (192.168.10.106)) + ":8082/",
and causing a syntax error:
Uncaught SyntaxError: Unexpected number jsx.js:11100
my-local-ip exports a string. wtf?
*/
// …
"plugins": [
// …
new Webpack.DefinePlugin({
"SERVER_IP": require("my-local-ip")()
}),
],
//…
@alkhe
Copy link

alkhe commented Sep 14, 2015

In case anyone ever ends up here due to the same problem, the string needs to be enclosed in quotes.

If DefinePlugin sees a string, it will attempt to replace it verbatim into the source.

You can do '"' + require("my-local-ip")() + '"' or simply JSON.stringify(require("my-local-ip")()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment