gpmf-extract
gpmf-extract copied to clipboard
"Uncaught ReferenceError: global is not defined at..." when using with webpack (Angular 10^)
First of all, thanks for developing this wonderful tool!
On the issue: when using the package in a browser project with webpack, in our case Angular, and importing it with import * as GpmfExtract from 'gpmf-extract';
, we receive this error: Uncaught ReferenceError: global is not defined at...
which seems to stem from the inline-worker: var WORKER_ENABLED = !!(global === global.window && global.URL && global.Blob && global.Worker);
For the moment, the solution is to declare (window as any).global = window;
in the project's polyfills.ts file, but this feels more like a temporary fix than a proper usage.
Thanks for the report. I personally don't have experience with Angular or TypeScript, so I would appreciate it if someone else suggested a fix for this. Otherwise I'll have a look whenever I find a spare moment.
The module works well in Webpack if using the require syntax.
var gpmfExtract = require('gpmf-extract');
The problem is that global
is not defined outside of NodeJS. To solve this a globalThis
variable was made that is defined both in nodeJS and in the browser. Switching to that should fix the problem. To be more compatible, you could define global as this:
const myGlobal = typeof globalThis ? globalThis : typeof global ? global : window;
Sounds reasonable. PR welcome
This should be fixed now :)