Nodejs 版本:4.4.7 NPM 版本:2.15.8
我正在运行以下代码,该代码是从以下 URL 复制而来的
https://kafka.js.org/docs/getting-started
const { Kafka } = require('kafkajs')
const kafka = new Kafka({
clientId: 'my-app',
brokers: ['kafka1:9092', 'kafka2:9092']
})
上面的代码保存在“simpleapp”文件夹下的“apps.js”文件中。除此之外,我还安装了以下
npm install kafkajs
当我运行 app.js 文件时,出现以下错误
/Users/nick/Documents/nodeprojects/simpleapp/apps.js:1
(function (exports, require, module, __filename, __dirname) { const { Kafka } = require('kafkajs')
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
问题是什么?