fix(docker): polyfill DOMMatrix/ImageData/Path2D for pdfjs-dist in linux/amd64 container via NODE_OPTIONS --require
This commit is contained in:
23
teressa-copeland-homes/src/instrumentation.ts
Normal file
23
teressa-copeland-homes/src/instrumentation.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Next.js instrumentation hook — runs once before any route handler.
|
||||
* Polyfills browser globals required by pdfjs-dist at module load time.
|
||||
* @napi-rs/canvas normally provides these but may be absent in some server
|
||||
* environments (e.g. linux/amd64 Docker image on ARM build host).
|
||||
* Text extraction never actually calls these — pdfjs needs the classes defined.
|
||||
*/
|
||||
export async function register() {
|
||||
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
||||
if (typeof globalThis.DOMMatrix === 'undefined') {
|
||||
// @ts-expect-error minimal stub
|
||||
globalThis.DOMMatrix = class DOMMatrix { constructor() { return this; } };
|
||||
}
|
||||
if (typeof globalThis.ImageData === 'undefined') {
|
||||
// @ts-expect-error minimal stub
|
||||
globalThis.ImageData = class ImageData { constructor() { return this; } };
|
||||
}
|
||||
if (typeof globalThis.Path2D === 'undefined') {
|
||||
// @ts-expect-error minimal stub
|
||||
globalThis.Path2D = class Path2D { constructor() { return this; } };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user