1

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

1
  • 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#defineplugin Commented May 9, 2016 at 9:15

1 Answer 1

1

define object in some file like below

var data={

  myvarname:""

};

and call where you want like this

data.myvarname;

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, but I cannot make any modifications in data.js file as mentioned in the description. I want to handle it from outside.
ok define your vairable in other js as posted in my answer hope it will work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.