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.

Should process/browser.js be included in build due to require('jquery')?

See original GitHub issue

Description

Coincidence caused me to notice that the Node.js process/browser module is included in my brunch build. I have isolated it to use of jquery, though I see no request for “process” anywhere. Running “brunch b” puts a copy in public/app.js and also inserts the following right around the end of the file:

require.alias(“process/browser.js”, “process”);process = require(‘process’);

Is inclusion of “process” correct behavior by brunch, or at least to be expected? This does not seem right to me, but I am new to brunch, so it makes me wonder if I am doing something wrong.

Here is information about my test case:

Environment

  1. Brunch: 2.8.2
  2. Node: 6.5.0
  3. NPM: 3.10.3
  4. Operating system: Debian/jessie

package.json contents

{
  "name": "brunch-app",
  "description": "Description",
  "author": "Your Name",
  "version": "0.1.0",
  "repository": {
    "type": "git",
    "url": ""
  },
  "scripts": {
    "start": "brunch watch --server",
    "build": "brunch build --production"
  },
  "dependencies": {
    "jquery": "^3.1.0"
  },
  "devDependencies": {
    "brunch": "^2.0.0",
    "javascript-brunch": "^2.0.0",
    "css-brunch": "^2.0.0",
    "uglify-js-brunch": "^2.0.0",
    "clean-css-brunch": "^2.0.0",
    "auto-reload-brunch": "^2.0.0"
  }
}

brunch-config.js contents

exports.files = {
  javascripts: {joinTo: 'app.js'},
  stylesheets: {joinTo: 'app.css'},
  templates: {joinTo: 'app.js'}
};

app/initialize.js contents

// Test inclusion of jquery in the project:
var jq = require('jquery');

document.addEventListener('DOMContentLoaded', function() {
  // do your setup here
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pnmcostacommented, Aug 10, 2017

Umm, strangely when building on Win, the require(‘process’) is not added to the globals, only the alias.

Whereas on Linux, it does add it and caused the error.

So rather than ignore it, I just include process/browser.js with the concatenated jquery file.

this prevents the console error in the browser as it’s included in the first js file I request on my app.

1reaction
pnmcostacommented, Aug 8, 2017

@LMS007 adding /node_modules\/process\/browser.js/ to ignored in conventions seems to have worked for me:

  conventions:
    # we don't want javascripts in asset folders to be copied like the one in
    # the bootstrap assets folder
    assets: /assets\/(?!javascripts)/
    ignored: [
      /\/_/,
      /vendor\/(node|j?ruby-.+|bundle)\//,
      /node_modules\/process\/browser.js/
    ]

this is my setup on Win 10

  "dependencies": {
    "bootstrap-datepicker": "^1.6.4",
    "bootstrap-sass": "latest",
    "font-awesome": "^4.7.0",
    "fotorama": "^4.6.4",
    "fullcalendar": "^3.2.0",
    "jquery": "^3",
    "jquery-deparam": "^0.5.1",
    "jquery-socialshare": "latest"
  },
  "devDependencies": {
    "auto-reload-brunch": "~2.7.1",
    "brunch-static": "~1.2.1",
    "copycat-brunch": "~1.1.0",
    "grunt": "~1.0.1",
    "html-brunch-static": "~1.3.2",
    "pleeease-brunch": "~3.0.0",
    "sass-brunch": "~2.10.4",
    "uglify-js-brunch": "~2.10.0",
    "brunch": "~2.10.10"
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Node-style require for in-browser javascript? - Stack Overflow
Require -stub — provides node-compliant require in browser, resolves both modules and relative paths. Uses technic similar to TKRequire (XMLHttpRequest).
Read more >
An Introduction to jQuery | DigitalOcean
This guide will take you through the JavaScript jQuery library by covering how to install jQuery in a web project; the definitions of ......
Read more >
Handling common JavaScript problems - MDN Web Docs
The trouble with JavaScript​​ This is one of the main reasons why libraries like jQuery came into existence — to abstract away differences...
Read more >
RequireJS - Quick Guide - Tutorialspoint
RequireJS - Overview. RequireJS is a JavaScript library and file loader which manages the dependencies between JavaScript files and in modular programming.
Read more >
CoffeeScript
You can use any existing JavaScript library seamlessly from CoffeeScript (and ... Major new features in CoffeeScript 2 include async functions and JSX....
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