Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"not a constructor" error when initialising WebPubSubClient using Vite #27980

Open
3 tasks done
Chris-Greaves opened this issue Dec 4, 2023 · 2 comments
Open
3 tasks done
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. WebPubSub

Comments

@Chris-Greaves
Copy link

Chris-Greaves commented Dec 4, 2023

  • Package Name: @azure/web-pubsub-client
  • Package Version: ^1.0.0-beta.3
  • Operating system: Windows
  • nodejs
    • version: v21.1.0
  • browser
    • name/version: Google Chrome/119.0.6045.200
  • typescript
    • version: ^5.0.0

Describe the bug
Can't initialise a new WebPubSubClient instance in my Sveltekit project. I'm getting the error TypeError: import_events.default is not a constructor (see screenshot to show where)

To Reproduce
Steps to reproduce the behavior:

  1. Create a new skeleton Sveltekit project with Typescript: npm create svelte@latest bug-test
  2. Add the following code to the +page.svelte file
    <script lang="ts">
    import { WebPubSubClient } from '@azure/web-pubsub-client';
    
    let tokenUrl = "<add token url>";
    let client: WebPubSubClient;
    
    async function connect() {
    	client = new WebPubSubClient(tokenUrl);
    	await client.start();
    
    	client.on('connected', () => console.log('Web PubSub Connected'));
    	client.on('group-message', m => console.log('Message received: %s', JSON.stringify(m)));
    }
    </script>
    
    <button on:click={connect}>Connect</button>
    
  3. Run the server and click the button

Expected behavior
The client should be initialised so I can connect to the Web PubSub

Screenshots
image

Additional context
I'm not a frontend developer in any way, but I'll try my best to give as much info as possible.

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 4, 2023
@Chris-Greaves
Copy link
Author

Chris-Greaves commented Dec 5, 2023

Also fails in Edge and Firefox.

I noticed that the EventEmitter doesn't have curly brackets {} when it's imported.
image
src: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/web-pubsub/web-pubsub-client/src/webPubSubClient.ts#L6

If changing this would fix it, I don't mind doing a PR to change every instance of EventEmitter being imported to use curly brackets.

@c-richard
Copy link

c-richard commented Dec 5, 2023

We were able to workaround this issue by installing this events package as a dependency https://www.npmjs.com/package/events.

This seems like an issue using this library with vite -> vitejs/vite#7821

@xirzec xirzec added Client This issue points to a problem in the data-plane of the library. WebPubSub bug This issue requires a change to an existing behavior in the product in order to be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 5, 2023
@github-actions github-actions bot removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Dec 5, 2023
@Chris-Greaves Chris-Greaves changed the title "not a constructor" error when initialising WebPubSubClient using Sveltekit "not a constructor" error when initialising WebPubSubClient using Vite Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. WebPubSub
Projects
None yet
Development

No branches or pull requests

4 participants