TypeError: Object(...) is not a function at Object.randomInt
Opened this issue · 10 comments
Do you want to request a feature or report a bug?
Report a Bug
What is the current behavior?
When creating a new instance I see the following error in browser console:
pusher-js.js?v=405c2cf0:36109 Uncaught (in promise) TypeError: Object(...) is not a function
at Object.randomInt (pusher-js.js?v=405c2cf0:36109:57)
at new pusher_Pusher (pusher-js.js?v=405c2cf0:36654:43)
at new pusher_with_encryption_PusherWithEncryption (pusher-js.js?v=405c2cf0:36826:13)
at +page.svelte:17:9
If the current behavior is a bug, please provide the steps to reproduce and
if possible a minimal demo of the problem via https://jsfiddle.net or similar.
What is the expected behavior?
Pusher to intialize and work correctly
Which versions of Pusher, and which browsers / OS are affected by this issue?
Did this work in previous versions of Pusher? If so, which?
I tried many versions 7.4.0, 8.0.2 and 8.4.0-rc2
** MORE DETAILS
It is a sveltekit app which use vite.
It was working fine with sveltekit 1.x vite 4.x but now I need to upgrade.
The biggest difference is that the support for node modules was dropped, I am using the polyfill node modules from vite-plugin-node-polyfills
Following is my entire vite.config.ts
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills'
export default defineConfig({
plugins: [sveltekit(), nodePolyfills({
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: false,
},
})]
});
I was struggling with this for a while so I tried many different things that I found in answers in stackoverflow.
I will highly appreciate any help. or a working sveltekit example if possible.
Error happens at this code in the browser:
randomInt(max) {
return Object(external_crypto_["randomInt"])(max);
}
the problem seems to be that in browser there is no crypto module available.
I tried various ways to polyfill it but every attempt failed
Did you try https://www.npmjs.com/package/rollup-plugin-polyfill-node? this specifically includes polyfil for the crypto package.
Did you try https://www.npmjs.com/package/rollup-plugin-polyfill-node? this specifically includes polyfill for the crypto package.
Yes I did. That didn't work either. It does make an empty crypto
which doesn't have the function randomInt
.
Almost everywhere it says it is hard to polyfill crypto and should be avoided a best as possible.
If I am not able to fix this problem by next 2 days we will have no choice but to look for a Pusher alternative.
Getting the same error, any fix available?
@sambhav-gore did you find a solution?
@Gabotron-ES No I did not. We are planning to move to Ably now because of this.
So because of this bug, pusher is basically unable to work? lol such a a joke
@Gabotron-ES well, there is probably a fix or a workaround but I am too tied up with other development work plus my client doesn't have a lot of budget or time for me to research/fix. So basically 2-3 months ago he told me that if it works within next 2 days we fix or we move to a different provider (Ably). Since then we have parked the upgrade work for now which we will be taking up again in next month. Since I am personally happy with Pusher, I will give it one last try in the next month.
I see, good lucj and if you come up with a fix please notify us!