-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReferenceError when using npm package in the browser; get global object properly #71
Comments
Would not dream of saying such a thing. Who uses Bower anyway these days? ;-) Just update #72 to pass the linting and this should be fixed. |
Ah okay, I thought maybe not many folks at sinonjs were using Webpack, since sinon (before 2.0.0-pre) isn't Webpack-compatible. Working on fixing the jslint error... |
I messed up when rebasing and merging in your changes, as I didn't run the linting (which failed due to migrating to ESLint where we disallowed While just disabling that var lolex = require("./src/lolex-src.js");
var clock = lolex.install();
fn = function() { console.log('should show immediately'); }
setTimeout(fn, 15000); // Schedules with clock.setTimeout
clock.tick(20000); I compiled this using <script src="./out.js" ></script> What struck me was that this works without your patch in both the browser and in Node, so I am not sure which problem you are fixing? Could you please come up with the details necessary to recreate a failing testcase in the |
Sure, I wonder if it depends on the webpack config? I just checked and if I go into my chrome console and evaluate |
Yes, here it is: https://webpack.github.io/docs/configuration.html#node |
In any case wouldn't you want |
we could probably go with |
Okay, I think what happened was I was using |
In addition I think usage of |
Okay, repro is simple: just paste |
sigh the JS world can be so confusing these days. Yes, I was trying to use lolex as a webpack external so that I could use sinon 1.7 as a webpack external. I hadn't noticed that you basically require lolex to be built with browserify or webpack to use in the browser. In any case the |
It already does. It's in the top level directory, lolex.js, built by
|
Well I'm closing this as invalid. Sorry for the trouble |
No worries. This does show we need to update the docs, though. I see it says you need to build it yourself, which is incorrect. |
I know you might to say "use bower"...but no. React devs use npm for everything these days, including for the browser, and we're used to npm packages working in both node and the browser (i.e. via webpack).
Usually when I need access to the global object, I do
Works in node and the browser.
Alternative you could call your bootstrap function with
(see http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript)
Whether you want to use that or some other solution, please make sure that
src/lolex-src.js
works even if accessingglobal
would cause aReferenceError
.The text was updated successfully, but these errors were encountered: