Node module (@pusher/push-notifications-web) failing to import on refreshing page - nextjs

Viewed 168

facing this issue while integrating node module @pusher/push-notifications-web https://github.com/pusher/push-notifications-web

I am not sure if this is an issue with NextJs or with the node module itself.

Everything works fine when the pages load for the first time, but when by any chance if we refresh the page or redirect the user to a new page. I am getting this error

enter image description here

enter image description here

1 Answers

The issue can be fixed by transpiling @pusher/push-notifications-web module - which is exported as ESM - using next-transpile-modules in Next.js config:

// next.config.js
const withTM = require('next-transpile-modules')(['@pusher/push-notifications-web']);

module.exports = withTM({/* custom config */});
Related