local-storage: TypeError: Class constructor CustomEvent cannot be invoked without 'new'

When running tests with Jest & running our app on "@rehooks/local-storage": "2.4.1"

Details:

     at new LocalStorageChanged (node_modules/@rehooks/local-storage/src/local-storage-events.ts:21:9)
      at Object.writeStorage (node_modules/@rehooks/local-storage/src/local-storage-events.ts:54:30)
      at create (node_modules/@rehooks/local-storage/src/use-localstorage.ts:89:7)
      at apply (node_modules/react-dom/cjs/react-dom.development.js:23487:20)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)
      at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:315:27)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:266:3)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:212:11)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:144:23)
image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 44
  • Comments: 25 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I am having the same issue. For a quickfix you can rollback to 2.4.0. The breaking behavior was introduced by #67. I think the fix would be to implement the suggestion in this comment: https://github.com/rehooks/local-storage/pull/67#issuecomment-668833477

Reopening as it seems the issue is not resolved

When is that planned to be fixed? 2.4.1 is broken

I do get the same error with 2.4.3, reverting back to 2.4.0 works

I am still seeing this error after upgrading to 2.4.3. Is there anything else that needs to be done to fix this? Screen Shot 2021-09-07 at 9 17 14 AM

While I wait on getting access to publish to npmjs.com, I have published the 2.4.2 patch to GitHub packages instead, and have also published it under my own scope. Here is how you may use both alternatives:

Switch to @jharrilim/local-storage

Probably the simplest choice, just change your package.json entry that once said:

{
  "dependencies": {
    "@rehooks/local-storage": "^2.4.1"
  }
}

to:

{
  "dependencies": {
    "@jharrilim/local-storage": "^2.4.2"
  }
}

Use the GitHub package

A little more effort, but if it matters, it keeps you pulling from the same org. Add a .npmrc file to your repo if you don’t already have one, and ensure it has this line in it:

@rehooks:registry=https://npm.pkg.github.com

I can confirm that our CI started failing when we updated from 2.4.0 to 2.4.1.

@jharrilim the fix is released under 2.4.3 version on npm. I don’t have org access to rehooks to add you as a contributor to npm. Didn’t focus on this, as I was busy with my day job and don’t really use this package anymore. Thanks for keeping it maintained. I’ll try to be more active with publishing.

Do we have some plans to update the version on the npm? image

I am having the same issue. For a quickfix you can rollback to 2.4.0. The breaking behavior was introduced by #67. I think the fix would be to implement the suggestion in this comment: #67 (comment)

Thanks for suggesting the quickfix!

Any update on this?

I haven’t taken a look at this repo in a while so I might be a bit slow to boot, but I shall look into this tonight or sometime this week.

@jharrilim is it possible to make at least a working patch version? Everytime when doing a interactive upgrade this lib pops up in not making our build correctly anymore. Its not expectable that using a patch upgrade can give this behaviour. Thanks!

Agreed, and sorry for the inconvenience. We shall fix this sometime soon.

@spencerschack you are a life saver 🥇