web-push icon indicating copy to clipboard operation
web-push copied to clipboard

Cannot read property 'generateRequestDetails' of undefined on TypeScript version greater than 4.0.

Open ArthurMartiros opened this issue 3 years ago • 4 comments

Got problem with web-push package using with typescript version greater than 4.0 but it works fine on typescript versions lesser than 4.0. Environment info:

  • NodeJs Version: 14.17.6
  • Yarn Version: 1.22.11
  • web-push package version: 3.4.5

tsconfig.json:

{ "compilerOptions": { "outDir": "../out", "module": "commonjs", "target": "esnext", "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": true, "skipLibCheck": true, "declaration": false, "resolveJsonModule": true, "lib": [ "dom", "esnext", "esnext.asynciterable" ] }, "include": [ "./**/*" ] }

Error Message: TypeError: Cannot read property 'generateRequestDetails' of undefined

ArthurMartiros avatar Oct 21 '21 13:10 ArthurMartiros

I have the same issue.

LeoCreer avatar Nov 10 '21 11:11 LeoCreer

I also encounter this error with Typescript 4.3.5

beenotung avatar Nov 27 '21 07:11 beenotung

This library is exposing a singleton (instance object of a class), therefore it is not compatible with named import.

This doesn't work:

import { sendNotification } from 'web-push'

sendNotification(…)

But this works:

import * as webPush from 'web-push'

webPush.sendNotification(…)

We may include this importing guideline in the readme to help future users.

beenotung avatar Nov 27 '21 08:11 beenotung

We may include this importing guideline in the readme to help future users.

Sounds good to me, PRs welcome ;) I'd also be OK with a PR to somehow make named import feasible.

marco-c avatar May 02 '22 22:05 marco-c