Closed justinlittman closed 2 years ago
I would guess it's a packaging problem. We use global
to access the global namespace namespace in a couple of places; I'm not using Webpack myself, but I'm sure there is some convention how to convert it (presumably, either renaming global
to window
or by defining var global = window
as a global variable).
My understanding is that webpack is supposed to do that automagically: https://webpack.js.org/guides/ecma-script-modules/
Other ESM modules that the app uses are transpiled correctly, but I don't know if they use global
in the same way.
I don't think this is about ESM modules at all. Both browsers and Node.js support ESM nowadays, but this is still an ESM module written for Node.js: it depends on Node.js modules and the Node.js API, where there is a global variable global
to access the global namespace; in the Browser window
would be the equivalent. When transpiing for use in the browser, you need a solution for this. As this is very common, I suspect Webpack will have a solution for this if enabled in the config; otherwise you should be able to work around it easily by defining global = window
yourself before EDTF is loaded.
Did anyone come up with a nice solution to this?
I can't add const global = window
about import
without my linter screaming.
I haven't been able to add a new plugin which maps global.Date
to a safe Date it can use.
Would modifying src/date.js
like this work:
const Parent = (typeof window === 'undefined' ? global.Date : window.Date)
export class Date extends Parent {
Is this still about Webpack? In the docs it says that Webpack polyfills global by default so I wonder if this is Webpack issue?
That said, yes, it should be trivial to work around this by temporarily storing the original Date object in an extra variable.
we also ran into this issue. Why not use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis ? it should work for everyone
webpack5 doesn't provide polyfills for Node by default: https://stackoverflow.com/questions/64557638/how-to-polyfill-node-core-modules-in-webpack-5
Using globalThis
should be fine yes.
thanks a lot!
My apologies, but I cannot tell if this is a problem with the configuration of my React application or the packaging of edtf.js.
Using version 4.1.0 and 4.0.0, I get when running the application in a browser:
However, with 3.1.0 no error is received and edtf.js works as expected.
The webpack config is:
Thanks in advance for your assistance.