【问题标题】:Vue error running using node-rdkafka package使用node-rdkafka包运行Vue报错
【发布时间】:2022-11-17 10:10:14
【问题描述】:

我在我的应用程序中安装了 node-rdkafka。 npm 安装节点 rdkafka

在我的代码中。

import Kafka from 'node-rdkafka';

  created() {
    console.log(Kafka.features);
  }

运行时出错npm 运行开发

    ERROR in ./node_modules/node-rdkafka/lib/kafka-consumer-stream.js 14:15-41
Module not found: Error: Can't resolve 'stream' in '/root/Sites/NDE-Frontend/node_modules/node-rdkafka/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

ERROR in ./node_modules/node-rdkafka/lib/producer-stream.js 14:15-41
Module not found: Error: Can't resolve 'stream' in '/root/Sites/NDE-Frontend/node_modules/node-rdkafka/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

ERROR in ./node_modules/node-rdkafka/node_modules/bindings/bindings.js 5:9-22
Module not found: Error: Can't resolve 'fs' in '/root/Sites/NDE-Frontend/node_modules/node-rdkafka/node_modules/bindings'

ERROR in ./node_modules/node-rdkafka/node_modules/bindings/bindings.js 6:9-24
Module not found: Error: Can't resolve 'path' in '/root/Sites/NDE-Frontend/node_modules/node-rdkafka/node_modules/bindings'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ./node_modules/node-rdkafka/node_modules/file-uri-to-path/index.js 6:10-29
Module not found: Error: Can't resolve 'path' in '/root/Sites/NDE-Frontend/node_modules/node-rdkafka/node_modules/file-uri-to-path'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

webpack compiled with 5 errors
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @neubus/nde-frontend@ development: `mix`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @neubus/nde-frontend@ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-11-16T14_25_47_382Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @neubus/nde-frontend@ dev: `npm run development`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @neubus/nde-frontend@ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

有没有人遇到同样的问题?

【问题讨论】:

    标签: javascript vue.js apache-kafka kafka-consumer-api


    【解决方案1】:

    我只是将它添加到我的webpack.config.js 来解决这个问题。

            fallback: {
                "stream": false,
                "fs": false,
                "tls": false,
                "net": false,
                "path": false,
                "zlib": false,
                "http": false,
                "https": false,
                "stream": false,
                "crypto": false,
            }
    

    【讨论】:

      猜你喜欢
      • 2018-06-11
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      相关资源
      最近更新 更多