I am having trouble integrating https://www.npmjs.com/package/mqtt into my angular2 typescript project (created with angular-cli).
Using var mqtt = require('mqtt');
produces the error Cannot find name 'require'
Therefore I tried using import (as I normally would) by adding it to the modules.ts:
import { mqtt } from 'mqtt/mqtt';
...
imports: [
BrowserModule,
FormsModule,
HttpModule,
mqtt
],
I tried this with import { MQTT } from 'mqtt/mqtt';
and import { MqttClient } from 'mqtt/mqtt';
as well (the last one is exported as such in the mqtt.js
I even tried importing those in the classfile itself.
I am pretty sure this is a trivial error on my behalf but I cannot get my head around it.
(Note: "@types/node": "^7.0.0", is installed as well, so this won't work either)
my tsconfig:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"isolatedModules": false,
"jsx": "react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"noImplicitUseStrict": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"node_modules",
"typings/browser",
"typings/browser.d.ts"
],
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false,
"formatOnSave": true
}
}