Ability to ignore modules at least in well-known environments
See original GitHub issueThis is a 🙋 feature request.
I was trying to use parcel.js for an electron application. The goal is to have a lightweight HMR solution without the need to set up something complex. Besides I love the fine grained control you can get with module.hot.dispose and module.hot.accept.
parcel index.html
🤔 Expected Behavior
parcel.js should not bundle the electron package.
😯 Current Behavior
🚨 /Users/gimenete/projects/unicycle/unicycle/node_modules/electron/index.js: Could not statically evaluate fs call
Basically parcel is trying to bundle the electron package itself. Internally electron does things with the file system. I cannot control that, but even more: there’s no need to bundle electron itself with the code.
💁 Possible Solution
I like the idea of having well-known environment configurations, such as eslint does. So we could have:
parcel --env electron index.html
This would apply some additional rules to parcel due to the selected environment. For example ignoring electron or even ignoring all node_modules.
💻 Code Sample
As soon as you import electron itself:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
<script src="./hello.js"></script>
</body>
</html>
// hello.js
import * as electron from "electron";
console.log('hello world');
The build fails. The additional <script> with those deletes is due to this: https://github.com/parcel-bundler/parcel/issues/321 Which is another thing the --env idea could fix.
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.4.1 |
| Node | v8.9.1 |
| npm/Yarn | npm 5.5.1 |
| Operating System | macOS High Sierra |
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:11 (1 by maintainers)

Top Related StackOverflow Question
OK, it seems a workaround can be something like this, so Parcel won’t bundle it.
Or another solution is, if you need it in the renderer js entry file (which is bundled with Parcel), you can require it like this:
By using
evalparcel won’t bundle this, but in the runtime, it’ll be loaded normally.I toyed around with this by skipping in dependencies.js anything that looked like packages. I’m guessing Parcel’s previous require stuff would get stuff loaded, but I’m still studying how things get added to bundles. I’m going to keep throwing myself at it for a bit.