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.

Brunch global require conflicts with node local require

See original GitHub issue

Description

The bundle generated by brunch is not compatible with node’s environment, whenever I try to run the bundle in node for server rendering, I get something like:

TypeError: require.register is not a function

It is trying to use node’s require, and not brunch’s.

Since in node require is in the local context, so it takes precedence over brunch’s require, which is places in the global context.

Proposed solution

I think we could rename require to __require__ in commonjs-require-definition/require.js and within the bundle.

We could still export both __require__ and require to the global context.

Or we could remove commonjs-require-definition/require.js from its own scope, so at least inside the bundle it overrides node’s require (but this seems nasty).

I’m not sure if there is a better solution 😃

Environment

  1. Brunch: 2.8.2
  2. Node: v6.2.0
  3. NPM: 3.8.9
  4. Operating system: OS X El Capitan 10.11.6

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
etwarkcommented, Mar 8, 2018

@overallduka Great idea. I’ll give it a try and see what I come up with. Thanks!

0reactions
reubanocommented, Dec 17, 2018

@paulmedynski I think you miss-understood what @paulmillr is saying. Anyone can create a pull request (PR), you don’t have to be a maintainer. Once you successful create a PR, he will then be open to giving you commit access. Many projects operate this way to limit maintainer rights to those who have actually contributed to the project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Brunch require with node.js modules - Stack Overflow
I have Brunch set up for ease of compiling JS together, but want to also be able to use a node.js module with...
Read more >
Why the Hell Would I Use Node.js? A Case-by-case Tutorial
Node.js is a platform that fills a particular need, and understanding this is ... Installing packages locally prevents version conflicts at the global...
Read more >
The Issue With Global Node Packages - Smashing Magazine
I'm specifically talking about installing packages from npm globally using npm install -g . Don't get me wrong: Installing packages globally ...
Read more >
45 CFR Part 75 -- Uniform Administrative Requirements, Cost ...
Auditor means an auditor who is a public accountant, or a Federal, state, local government, or Indian Tribe audit organization, which meets the...
Read more >
Babel · The compiler for next generation JavaScript - Babel.js
Not suitable for libraries. The require hook automatically hooks itself into all node requires. This will pollute the global scope and introduce conflicts....
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