Can';t在Node.js 13.6中导入@google/pubsub和其他@google npm模块

Can';t在Node.js 13.6中导入@google/pubsub和其他@google npm模块,node.js,ecmascript-6,node-modules,google-cloud-pubsub,Node.js,Ecmascript 6,Node Modules,Google Cloud Pubsub,我正在进行物联网项目,我需要在app.js文件中使用@google cloud/pubsub npm模块!我想使用Node.js 13.6.0作为带有ECMAScript模块的Node.js版本 // TypeError: PubSub is not a constructor import PubSub from '@google-cloud/pubsub'; // SyntaxError: module does not provide an export name 'PubSub' i

我正在进行物联网项目,我需要在app.js文件中使用@google cloud/pubsub npm模块!我想使用Node.js 13.6.0作为带有ECMAScript模块的Node.js版本

// TypeError: PubSub is not a constructor 
import PubSub from '@google-cloud/pubsub';

// SyntaxError: module does not provide an export name 'PubSub'
import { PubSub } from '@google-cloud/pubsub';

// ReferenceError: require is not defined 
const PubSub = require('@google-cloud/pubsub');

我能够使用Node.js 13.6.0使用第一种方法导入PubSub:

// app.js
import PubSub from '@google-cloud/pubsub';
console.log(PubSub);

// Output
$ node app.js 
(node:17508) ExperimentalWarning: The ESM module loader is experimental.
{
  v1: {
    PublisherClient: [Function: PublisherClient],
    SubscriberClient: [Function: SubscriberClient]
  },
  IAM: [Function: IAM],
  PubSub: [Function: PubSub],
  Snapshot: [Function: Snapshot],
  Message: [Function: Message],
  Subscription: [Function: Subscription],
  Topic: [Function: Topic]
}
您是否安装了Node.js云发布/订阅客户端库

npm install --save @google-cloud/pubsub

我能够使用Node.js 13.6.0使用第一种方法导入PubSub:

// app.js
import PubSub from '@google-cloud/pubsub';
console.log(PubSub);

// Output
$ node app.js 
(node:17508) ExperimentalWarning: The ESM module loader is experimental.
{
  v1: {
    PublisherClient: [Function: PublisherClient],
    SubscriberClient: [Function: SubscriberClient]
  },
  IAM: [Function: IAM],
  PubSub: [Function: PubSub],
  Snapshot: [Function: Snapshot],
  Message: [Function: Message],
  Subscription: [Function: Subscription],
  Topic: [Function: Topic]
}
您是否安装了Node.js云发布/订阅客户端库

npm install --save @google-cloud/pubsub
实际上,我正在使用:

'use strict';
// Google Cloud PubSub  
const {PubSub} = require('@google-cloud/pubsub');
// Creates a client; cache this for further use
const pubSubClient = new PubSub();
实际上,我正在使用:

'use strict';
// Google Cloud PubSub  
const {PubSub} = require('@google-cloud/pubsub');
// Creates a client; cache this for further use
const pubSubClient = new PubSub();

对您是否尝试实例化并使用Publisher Client?是的,遵循此示例并使用PublisherClient创建主题对我很有效:您在导入模块或使用PublisherClient时遇到问题吗?是的。。。。您是否尝试实例化并使用Publisher Client?是的,遵循此示例并使用PublisherClient创建主题对我很有效:您在导入模块或使用PublisherClient时遇到问题吗?