Compatibility with bundling tools like webpack and rollup
See original GitHub issueA way to find binaries by contents of package.json files seems to be needed for compatibility with JS bundlers.
As this code in gRPC’s repo, we need to pass paths to package.json to the find(package_json_path, opts) function in lib/pre-binding.js currently.
However, when the paths to package.json are hard-coded in source files like the one of gRPC, bundling tools, such as webpack and rollup, cannot detect the dynamic loading of external files and end up creating bundled files which don’t work.
So, we need some function like findByPackageInfo(package_json_content, opts). Then, we can change the code of gRPC like:
var binary = require('node-pre-gyp/lib/pre-binding');
var path = require('path');
var binding_path = binary.findByPackageInfo(require('../../../package.json'));
var binding = require(binding_path);
Any thoughts?
References
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Comparing bundlers: Webpack, Rollup & Parcel | js@imaginea
Module Bundling, on a high level, is a process of integrating together a group of modules in a single file so that multiple...
Read more >Rollup vs. Webpack -- A Comparison - OpenReplay Blog
Let's examine how these tools for managing dependencies operate. Dependency graph generation and eventual bundling are the two stages of a ...
Read more >a guide to build tools + exploring Webpack, Parcel, Rollup, ES ...
This is post # 54 of the series, dedicated to exploring JavaScript and its building components. In the process of identifying and describing ......
Read more >Rollup vs. Parcel vs. webpack: Which Is the Best Bundler?
For those coming from a non-JavaScript background, a bundler is a tool that ... Suppose your code is not bundled and hosted as...
Read more >Comparing the New Generation of Build Tools - CSS-Tricks
Whether we use webpack, Rollup, or Parcel for a development server, ... esbuild works with JSON files and can bundle them into JavaScript ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

If anyone comes here looking for a solution for Webpack, this fixed the problem for us:
Simply replace
sqlite3with the the dependency that usesnode-pre-gyp(in our case,argon2)This pull request https://github.com/mapbox/node-pre-gyp/pull/622 solves the main problem that prevents @mapbox/node-pre-gyp from working with webpack.
webpack needs to know where package.json and the .node file are located during the build process. Right now both locations are determined at run-time instead of during the build process.
Using
externalsas described above is a valid workaround, but it requires that the package is available at run-time. This means that after you build with webpack, you need to runnpm install package. It would be better if we could avoidnpm install packagesince it adds an extra step.@springmeyer a couple reasons webpack is useful include
Say you have a node app written in Typescript. You normally have to convert the Typescript (server.ts) to Javascript (server.js), and then run
node server.js. If you make a change to server.ts you now need to recompile the Typescript to Javascript, stop server.js, and re-run server.js. With webpack you can make a change to server.ts, and you don’t need to recompile, stop the server, and re-run the server. It does all of those steps for you. You could use nodemon and typescript watch instead of webpack for this though.If you have a node project with many relative imports, for example
import '../../../../src/file.js'the code can become unreadable. With webpack we can get rid of every …/ and write code that looks cleaner,import 'src/file.js'in this example.You could argue that webpack isn’t necessary (it’s much more useful for front-end development than back-end development), but you might be stuck using a node framework that depends on webpack.