-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use babel-loader in webpack #720
Comments
I acutally don't know what this is. I've used webpack to bundle this several times. |
The error is because the main file defined in package.json Reference: webpack/webpack#4603 The way around it atm is to use a loader in webpack that ignores the shebang line like https://github.com/javascriptismagic/shebang-loader |
Same problem here and the shebang loader doesn't seem to work on my side. |
If the shebang-loader doesn't work for whatever reason or is too complex to set up, you can try using the built-in NormalModuleReplacementPlugin from Webpack. Just add the following to your webpack.config.js file: var webpack = require("webpack");
module.exports = {
// ... other webpack config ...
plugins: [
new webpack.NormalModuleReplacementPlugin(/^mqtt$/, "mqtt/dist/mqtt.js"),
],
}; This essentially tells Webpack whenever it sees |
@mcollina Would it be possible to put the CLI and the MQTT library in separate files somehow? Putting them in a single file like this is obviously causing problems because the #! line at the top is not a valid JS syntax, and it interferes with all kinds of JS parsers (Webpack, Babel, Uglify, etc). |
Definitely, but why https://github.com/mqttjs/MQTT.js/blob/master/package.json#L60 is not recognized anymore? |
@mcollina I am not sure why the "browser" field in your package.json is not respected. If I had to guess, the problem is most likely with older bundlers/loaders from before the browser field spec was created. I just checked that Webpack 4 loads and packages your library just fine, but earlier versions of Webpack throw an error, which would seem to confirm the theory above. I guess with time this problem will go away, as more and more people upgrade to latest Webpack/Babel/etc. But for the time being many projects are stuck with older versions of Webpack that have this issue. |
Works for me:
|
I'm integrating mqtt to my electron app, and this works for me. |
I am trying the solution sypplied by @grnch . It compiles but then it runes into the issue caused by the fact that |
This is an automated message to let you know that this issue has If this issue is still important, you can simply comment with a Thank you for your contribution. |
This issue was automatically closed due to inactivity. |
ERROR in ./node_modules/mqtt/mqtt.js
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| #!/usr/bin/env node
| 'use strict'
The text was updated successfully, but these errors were encountered: