I'm using React JS with webpack, webpack-dev-server and Ecmascript 6. I have an undeclared variable in the file named data.js. However, I cannot modify the data.js file since its standard. So is there a way by which I can make the variable global from another js file? I tried declaring window.myvarnamein another file where data.js is referenced using import statement but its still giving an error Uncaught ReferenceError: myvarname is not defined
-
Could you provide the full error message you're getting as well as the stack trace? Is this error happening on the client side, or during webpack build? Also, if data.js is a module, it's weird for it to need to access a global variable. But in any case, you might want to use this webpack plugin to define a global variable: webpack.github.io/docs/list-of-plugins.html#definepluginAndrew Chen– Andrew Chen2016-05-09 09:15:42 +00:00Commented May 9, 2016 at 9:15
Add a comment
|
1 Answer
define object in some file like below
var data={
myvarname:""
};
and call where you want like this
data.myvarname;
2 Comments
Rahul Dagli
Sorry, but I cannot make any modifications in data.js file as mentioned in the description. I want to handle it from outside.
Muhammad Waqas
ok define your vairable in other js as posted in my answer hope it will work