你的问题很简单。如果你看
mqtt.js
它的内容是
$ ls
bin CONTRIBUTING.md dist doc examples lib LICENSE.md mqtt.js node_modules package.json README.md test types
$ cat mqtt.js
#!/usr/bin/env node
'use strict'
/*
* Copyright (c) 2015-2015 MQTT.js contributors.
* Copyright (c) 2011-2014 Adam Rudd.
*
* See LICENSE for more information
*/
var MqttClient = require('./lib/client')
var connect = require('./lib/connect')
var Store = require('./lib/store')
module.exports.connect = connect
// Expose MqttClient
module.exports.MqttClient = MqttClient
module.exports.Client = MqttClient
module.exports.Store = Store
function cli () {
var commist = require('commist')()
var helpMe = require('help-me')()
commist.register('publish', require('./bin/pub'))
commist.register('subscribe', require('./bin/sub'))
commist.register('version', function () {
console.log('MQTT.js version:', require('./package.json').version)
})
commist.register('help', helpMe.toStdout)
if (commist.parse(process.argv.slice(2)) !== null) {
console.log('No such command:', process.argv[2], '\n')
helpMe.toStdout()
}
}
if (require.main === module) {
cli()
}
现在这应该是
cli
不直接摄入。但如果你看到
dist
文件夹,其中包括另一个
mqtt.js公司
.这是你应该使用的。所以改变了
import {connect} from 'mqtt';
到
import {connect} from 'mqtt/dist/mqtt';
重新构建解决了这个问题
[1] Hash: 23e55c27224c66d940890aee1c472502b9e9a7e0
Version: webpack 3.12.0
Child client:
Hash: 23e55c27224c66d94089
Time: 10477ms
Asset Size Chunks Chunk Names
client.js 311 kB 0 [emitted] [big] main
styles.css 246 bytes 0 [emitted] main
[7] (webpack)/buildin/global.js 509 bytes {0} [built]
[] -> factory:229ms building:43ms = 272ms
[27] ./src/client.jsx 606 bytes {0} [built]
factory:144ms building:145ms = 289ms
[65] ./src/app/App.jsx 7.94 kB {0} [built]
[] -> factory:6ms building:195ms dependencies:5ms = 206ms
[74] ./src/styles/styles.pcss 151 bytes {0} [built]
[] -> factory:2556ms building:2927ms = 5483ms
+ 75 hidden modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--1-2!node_modules/postcss-loader/lib/index.js??ref--1-3!src/styles/styles.pcss:
[0] ./node_modules/css-loader??ref--1-2!./node_modules/postcss-loader/lib??ref--1-3!./src/styles/styles.pcss 530 bytes {0} [built]
factory:95ms building:838ms = 933ms
+ 1 hidden module
Child server:
Hash: 0aee1c472502b9e9a7e0
Time: 10465ms
Asset Size Chunks Chunk Names
server.js 237 kB 0 [emitted] main
stats.json 0 bytes [emitted]
[54] ./src/server.jsx 1.28 kB {0} [built]
factory:17ms building:254ms = 271ms
[98] ./src/app/template.jsx 622 bytes {0} [built]
[] -> factory:17ms building:16ms = 33ms
[99] ./src/app/App.jsx 7.94 kB {0} [built]
[] -> factory:18ms building:120ms dependencies:79ms = 217ms
[100] ./src/styles/styles.pcss 1.4 kB {0} [built]
[] -> factory:2621ms building:4ms = 2625ms
[101] ./node_modules/css-loader??ref--1-1!./node_modules/postcss-loader/lib??ref--1-2!./src/styles/styles.pcss 530 bytes {0} [built]
[] -> factory:9ms building:918ms = 927ms
+ 132 hidden modules