Checking validity of types works locally but not on netlify

  • flourishing-gelato-25d480
  • pnpm build works locally
  • fails on checking validity of types

I think this is due to including “webworker” lib in my typescript config? It seems to only be failing in my worker script. Here is a snippet for which the types fail to compile

self.addEventListener('install', function (event: ExtendableEvent) {
  console.log("Worker installed");
  event.waitUntil(self.skipWaiting()); // Activate worker immediately
});
self.addEventListener('activate', function (event: ExtendableEvent) {
  console.log("Worker activated");
  event.waitUntil(self.clients.claim()); // Become available to all pages
});

The error messages I’m seeing:

12:11:38 PM: - info Checking validity of types...
12:11:43 PM: Failed to compile.
12:11:43 PM: 
12:11:43 PM: ./src/worker.ts:83:34
12:11:43 PM: Type error: No overload matches this call.
12:11:43 PM:   Overload 1 of 3, '(type: "message", listener: (this: Window, ev: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions | undefined): void', gave the following error.
12:11:43 PM:     Argument of type '(e: ExtendableMessageEvent) => void' is not assignable to parameter of type '(this: Window, ev: MessageEvent<any>) => any'.
12:11:43 PM:       Types of parameters 'e' and 'ev' are incompatible.
12:11:43 PM:         Property 'waitUntil' is missing in type 'MessageEvent<any>' but required in type 'ExtendableMessageEvent'.
12:11:43 PM:   Overload 2 of 3, '(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void', gave the following error.
12:11:43 PM:     Argument of type '(e: ExtendableMessageEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
12:11:43 PM:       Type '(e: ExtendableMessageEvent) => void' is not assignable to type 'EventListener'.
12:11:43 PM:         Types of parameters 'e' and 'evt' are incompatible.
12:11:43 PM:           Type 'Event' is missing the following properties from type 'ExtendableMessageEvent': data, lastEventId, origin, ports, and 2 more.
12:11:43 PM:   Overload 3 of 3, '(type: "message", listener: (this: DedicatedWorkerGlobalScope, ev: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions | undefined): void', gave the following error.
12:11:43 PM:     Argument of type '(e: ExtendableMessageEvent) => void' is not assignable to parameter of type '(this: DedicatedWorkerGlobalScope, ev: MessageEvent<any>) => any'.
12:11:43 PM:       Types of parameters 'e' and 'ev' are incompatible.
12:11:43 PM:         Type 'MessageEvent<any>' is not assignable to type 'ExtendableMessageEvent'.

I can hack around the first error by changing the type to any but I’d like to keep the types.

12:40:26 PM: - info Checking validity of types...
12:40:31 PM: Failed to compile.
12:40:31 PM: 
12:40:31 PM: ./src/worker.ts:86:24
12:40:31 PM: Type error: Property 'skipWaiting' does not exist on type 'Window & typeof globalThis'.
12:40:31 PM:   84 | self.addEventListener('install', function (event: any) {
12:40:31 PM:   85 |   console.log("Worker installed");
12:40:31 PM: > 86 |   event.waitUntil(self.skipWaiting()); // Activate worker immediately
12:40:31 PM:      |                        ^
12:40:31 PM:   87 | });
12:40:31 PM:   88 | self.addEventListener('activate', function (event: any) {
12:40:31 PM:   89 |   console.log("Worker activated");

tsconfig.ts

{
  "compilerOptions": {
    "target": "esnext",
    "lib": ["esnext", "webworker", "dom", "dom.iterable"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "~/*": ["./src/*"],
      "@/*": ["./*"]
    }
  },
  "ts-node": {
    "esm": true,
    "compilerOptions": {
      "module": "nodenext",
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "migrate.ts", "src/middleware.ts.bak"],
  "exclude": ["node_modules"]
}

I’d appreciate any help! I saw one other thread on here with a similar issue but it was never resolved and got closed.

Netlify is not doing anything special with your code than run the commands you ask it to. So if you’e verified:

  1. All the depencies are the same version on Netlify as locally
  2. Node.js version is same
  3. The issue cannot be reproduced on a Ubuntu machine

Then, I believe you’d have to share a demo repo that shows this issue.