Repository navigation
node target should ignore hashbang #2168
Description
Activity
upvote
upvote
Did you find a workaround ? I have this problem with vendor JSONStream lib, don't know what to do !
- Reacted by Alexandre Hervé
Hey @martriay, I'm having the same issue, but I'm unclear on how to use shebang-loader. Is it used in the
webpack.config.jsfile? Could you post a snippet of it in use? Thanks.Reacted by Kielan, Joseph Richardson, Jon Smithers, Harshit Thukral, the way of learning, DeedleFake, S. Mahdi Mir-Ismaili and Duygu Altinok@komplexb sure! As I had troubles with the
JSONStreamlib, my loader looks like this:{ test: /node_modules\/JSONStream\/index\.js$/, loaders: ['shebang', 'babel'] }@martriay thanks for that.
So it's ignoring it, as in the shebang no longer stops my build. But I assumed it would leave the#!/usr/bin/env node --harmonyat the top of my built file; or is that not how it works?module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: ['shebang', 'babel'], } ] },Reacted by Amer Lotfi OrimiReacted by Amer Lotfi OrimiAny update on this? It seems like it might be a good feature to be built in, so that external packages don't need to be updated (as the hashbang is allowed by node).
Reacted by Petr Riabinin, Erik Isaksen, Caleb Rutan, Kirill Potekhin, Kyle Decot, Shibo Yao, Danny Mayer, Emmanuel Quentin, Jared Szechy, DeedleFake and 7 moreReacted by Cory Simmons, Kyle Decot, Emmanuel Quentin and BernardAny update this?
how is there not a solution to this. the only recommended shebang package doesn't even explain how to use it on it's own github page.
Reacted by Wouter Vanherck, Ross, Yaroslav, DeedleFake, Julian Montez, S. Mahdi Mir-Ismaili, Duygu Altinok, Guilherme Reis, Elisabetta, Forrest Burton and 1 moreReacted by Cláudio Margulhano and Joseph RichardsonAlso running into this. Any update on an "official" fix?
Where do i drop the code
{ test: /node_modules\/JSONStream\/index\.js$/, loaders: ['shebang', 'babel'] }any updates on this fix?
Also running into this issue. This is affecting our web scale. Please fix.
upvote
To use in latest versions of webpack:
module: { rules: [ ... { test: /FILE_NAME/, loader: 'shebang-loader', include: [/node_modules\/MODULE_NAME/] }, ... ] }Reacted by imerkle and Forrest Burtonshebang-loadernot working used the above ^^ code with webpack 3Reacted by Jeff Margolis and DelayReacted by CaerusKaruIf you want to use
shebang-loaderand you are on Windows the following will work on webpack 3:module: { rules: [ { test: path.resolve(__dirname, 'node_modules/jsonstream/index.js'), use: 'shebang-loader', }, ], },The above solutions are not working on Windows because of the path separators (
/vs\)I'm having the same problem with the sqlite3 library when using it with electron and create-react-app, where I have no access to the Webpack (would like not to have to eject).
@mnemanja What you can do as a last resort is import it with the ! syntax
import * as sqlite3 from 'shebang-loader!sqlite3';Problem is if you intend to write tests... This approach will break your jest tests since it does not use webpack. To fix it, you'd have to eject to be able to configure jest. Ironic right?
In my specific case of
JSONStreamI ended up using a fork, jsonstream2, which got rid of the shebang line, among other things. You could maybe do that too with sqlite3.Good luck!
@fxlemire Thanks for the suggestion!
I'll change the approach that I'm taking so that I'm going over the main process (in the structure my main process file is in the public folder so I was looking for an alternative and handle everything from inside of the render process).
Have a nice weekend :)
Reacted by François-Xavier LemireFor cross OS regex match, use this expression:
include: /node_modules[/\\]MODULE_NAME/this will work in windows and linux environments alike.
This one is tested with webpack3 on Windows and works:
module: { rules: [ { test: /node_modules[/\\]jsonstream/i , loader: 'shebang-loader' } ] }
Reacted by Glavin Wiechert, John Frades, cawfree, Mateja Petrovic, Guilherme Reis, Alex Shatberashvili and Shawn WilliamsReacted by cawfreein your module.exports at webpack.config.js include
externals: { "JSONStream": "require('JSONStream')" },
and if you are in a Electron or Node environment don't forget to set target
target: 'electron-renderer',Superseded by #4603
Any update to reflect this within webpack itself?
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
When building for the
nodetarget, the hashbang should be ignored. For example, if you have a file that hasrequire("JSONStream")you will get an error because this library's main file includes a hashbangThe node interpreter itself will ignore the hashbang if you run the file, but webpack will treat this as an error.