无法在带有 @pusher/push-notifications-web nodejs 的模块外部使用 import 语句 - beams
我正在尝试使用nodejs和express来遵循本教程: https://pusher .com/docs/beams/reference/web/#npm-yarn
首先,我做了:在添加代码之前 npm install @pusher/push-notifications-web 。
但是当我在 index.js 文件中添加此代码时:
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 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:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该错误是由于您尝试在常规 CommonJS 文件中使用 ES 模块特定功能(Node.js 中的默认行为)而引起的。但是,您看到的是 Pusher 的 Web SDK,它不会帮助您实现目标。
您需要 Node.js 的服务器 SDK - https://pusher.com /docs/beams/reference/server-sdk-node/。
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/.
验证您是否安装了最新版本的 Node.js,并且有两种方法可以修复
.mjs
作为文件扩展名,而不是.js
。Verify that you have the latest version of Node.js installed and you have 2 ways of fixing that
.mjs
as file extension instead of.js
.