How to include mqtt.js in an @angular/cli library

478 Views Asked by At

I've built https://www.npmjs.com/package/ngx-mqtt and am curently stuck with the issue that angular and it's ecosystem changed over time in a way, that transpiling mqtt.js with node polyfills doesn't work anymore. I once had a complete custom build setup, but switched to @angular/cli, but I don't find a way to either do the aforementioned or include a browserified mqtt.js into the build.

Has anybody experience with including a browserified javascript files into an @angular/cli library?

1

There are 1 best solutions below

0
On

the problem with the mqtt.js in typescript is that polyfills.ts is not working because its deprecated. It will show you that error

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: { "process": require.resolve("process/browser") }'
        - install 'process' If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "process": false }

so you can fix that with the npm command npm install util process so you can use mqtt.js insteat of ngx-mqtt because its only a wrapper and is also causes small performance issues