Uncaught ReferenceError: setImmediate is not defined
Closed this issue · 13 comments
When use with webpack, there maybe an Exception thrown out under some condition.
Could you explain more about what the precise issue is? What does mqtt
have to do with it?
We can not assumesetImmediate
defined globally, when packed with webpack
, the code will be like this:
// ...
// setimmediate attaches itself to the global object
__webpack_require__(123);
exports.setImmediate = setImmediate; // here, exception thrown out when `setImmediate` is not defined globally.
exports.clearImmediate = clearImmediate; // and here, too.
// ...
I guess I am still missing something... If setImmediate
gets attached to the global, then why is it not available? Sorry to go back and forth about something like this, but I just want to make sure I understand the problem. 😅
My understanding is that Webpack has been using the current version of this library for a while now, so what's special about your case that's triggering an issue only now?
I am using it neither in browser nor node. there is no window
,global
,setImmediate
,clearImmediat
defined.
If setImmediate gets attached to the global
Actually, setImmediate
is not always exist, and i don't use this function at all, but if packed and run not in browser or node, this will be a Exception in strict mode. Even remove this two lines code will work for me.
I am using it neither in browser nor node. there is no window,global,setImmediate,clearImmediat defined.
From my read of the code in setimmediate
, it should be able to successfully attach if the environment has any of this
, self
, or global
available as objects.
What kind of environment are you using that doesn't have any of those? I feel like there must be other things that break in similar ways as well...
I am working on a container you can find here: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html , if you could read chinese. I think it's like Electron
some how, but not exactly.
It's much more like nashorn, I think.
Hmm, I see, interesting! Shouldn't it have this
available at least though? That seems pretty fundamental...
I never use this
except in a typescript class, so I have not ever tried this
yet.
Check the PR above, in the mean time you can fix this issue by adding this to the plugins in your webpack build config:
plugins: [
new webpack.ProvidePlugin({
setImmediate: ['setimmediate', 'setImmedate'],
clearImmediate: ['setimmediate', 'clearImmedate']
}),
]