Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot use import statement outside a module with @pusher/push-notifications-web nodejs – beams

I am trying to follow this tutorial using nodejs and express: https://pusher.com/docs/beams/reference/web/#npm-yarn

First I did: npm install @pusher/push-notifications-web before adding the code.

But when I add this code in the index.js file:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import * as PusherPushNotifications from "@pusher/push-notifications-web";

const beamsClient = new PusherPushNotifications.Client({
  instanceId: "<YOUR_INSTANCE_ID_HERE>",
});

beamsClient.start().then(() => {
  // Build something beatiful 🌈
});

I get this error:
SyntaxError: Cannot use import statement outside a module

It’s also not very clear to me from the tutorial if the code has to be in the frontend or the backend. I tried both but got the same result.

How can I fix this problem?

>Solution :

The error is caused by the fact that you’re trying to use ES module specific features in a regular CommonJS file (the default behavior in Node.js). However, what you’re looking at is the Web SDK for Pusher which won’t help you achieve your goals.

You need the server SDK for Node.js – https://pusher.com/docs/beams/reference/server-sdk-node/.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading