JS / HTML + Webpack + @ azure / event-hubs:“ a:w(...)不是函数”

时间:2018-12-03 12:23:38

标签: javascript webpack es6-promise

我正在尝试使用@ azure / event-hubs npm软件包(https://www.npmjs.com/package/@azure/event-hubs),但是以下代码引发错误,我进行了一些搜索,但实际上似乎无法弄清楚。 (可能是我犯下了一些愚蠢的错误,但我确实需要帮助才能找到它)。我将所有内容与webpack捆绑在一起,然后在script标签中使用它。

代码:

const { EventHubClient, EventPosition } = require('@azure/event-hubs');

const client = EventHubClient.createFromConnectionString(process.env["EVENTHUB_CONNECTION_STRING"], process.env["EVENTHUB_NAME"]);

async function main() {
  const onError = (err) => {
    console.log("An error occurred on the receiver ", err);
  };

  const onMessage = (eventData) => {
    console.log(eventData.body);
    const enqueuedTime = eventData.annotations["x-opt-enqueued-time"];
    console.log("Enqueued Time: ", enqueuedTime);
  };

  const receiveHandler = client.receive("1", onMessage, onError, { eventPosition: EventPosition.fromEnqueuedTime(Date.now()) });

  // To stop receiving events later on...
  await receiveHandler.stop();
}

main().catch((err) => {
  console.log(err);
});

错误(路径已被“ ....”删除):

An error occurred on the receiver  a: w(...) is not a function
    at E._connect (file:///....../main.js:165:76736)
    at E.connect (file:///...../main.js:165:76246)
    at Promise (file:///..../main.js:30:205093)
    at new Promise (<anonymous>)
    at t.Connection.open (file:///..../main.js:30:204061)
    at connection.isOpen.c.defaultLock.acquire (file:///..../main.js:157:128551)
    at file:///..../main.js:165:123499
    at r._promiseTry (file://...../main.js:165:124491)
    at l (file:///...../main.js:165:123469)
    at r.acquire (file:///...../main.js:165:123961)

webpack.config.js:

const path = require('path');

module.exports = {
    entry: './www/src/index.js',
    output: {
        filename: 'main.js',
        path: path.resolve(__dirname, 'www/dist')
    },
    node: {
        fs: 'empty',
        net: 'empty',
        tls: 'empty'
    }
};

感谢您的帮助!

0 个答案:

没有答案