question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to ignore modules at least in well-known environments

See original GitHub issue

This 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
morajabicommented, Jan 26, 2018

OK, it seems a workaround can be something like this, so Parcel won’t bundle it.

<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script>
    window.nodeRequire = require;
    delete window.require;
    delete window.exports;
    delete window.module;
    const electron = nodeRequire('electron');
  </script>
</head>

<body>
  <div id="root"></div>
  <script src="./index.js"></script>
</body>

</html>

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:

// renderer.js
const electron = eval(`require('electron')`) /* or nodeRequire if you changed it */

By using eval parcel won’t bundle this, but in the runtime, it’ll be loaded normally.

2reactions
astra137commented, Jan 24, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attention – PSYC 100: Principles of Psychology F22
Selective attention is the ability to select certain stimuli in the environment to process, while ignoring distracting information. One way to get an...
Read more >
Command-line API | Node.js v19.3.0 Documentation
When FORCE_COLOR is used and set to a supported value, both the NO_COLOR , and NODE_DISABLE_COLORS environment variables are ignored. Any other value...
Read more >
Skip a submodule during a Maven build - Stack Overflow
The syntax to exclude multiple module is the same as the inclusion mvn -pl '!submodule1,!submodule2' install mvn -pl -submodule1,-submodule2 ...
Read more >
3. Using GHCi — Glasgow Haskell Compiler 9.4.4 User's Guide
Answer: it looks for the file M.hs , or M.lhs . This means that for most modules, the module name must match the...
Read more >
Remote Development FAQ - Visual Studio Code
Being able to develop in an environment that matches the target deployment environment. ... Visual Studio Code Remote Development uses existing, well known...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found