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.

Problems if `node_modules/` is a symlink

See original GitHub issue

Description

brunch gets problems if node_modules/ is a symlink.

Expected behavior

The build should have produced the exact same output as when node_modules/ was not a symlink.

Actual behavior

brunch generates syntactically valid JavaScript, but the JavaScript causes runtime errors. More details below.

Environment

  1. Brunch: 2.9.1
  2. Node: 6.9.1
  3. NPM: 3.10.8
  4. Operating system: Ubuntu 16.04

package.json contents

{
  "private": true,
  "devDependencies": {
    "brunch": "^2.9.1",
    "javascript-brunch": "^2.0.0"
  },
  "dependencies": {
    "jquery": "^3.1.1"
  }
}

brunch config contents

module.exports = {
  files: {
    javascripts: {
      joinTo: 'app.js'
    }
  },
  conventions: {
    // This is the default `conventions.vendor` value. If this line is commented
    // out, the problems strangely go away! However, I need to set this to
    // something else in my real project.
    vendor: /^(bower_components|node_modules|vendor)\//,
  },
}

Other useful files, when present (log, bower.json etc.)

app/app.js:

require('jquery')

Steps to reproduce

  1. Put the above files in a directory and cd into it.
  2. npm install
  3. mv node_modules ../node_modules
  4. ln -s ../node_modules/ node_modules
  5. brunch b

Look at this part of public/app.js:

require.register("node_modules/process/browser.js", function(exports, require, module) {

require.register("process/browser.js", function(exports, require, module) {
  require = __makeRelativeRequire(require, {}, "process");

Note how there is a require.register inside another require.register! That causes the following runtime error:

Error: Cannot find module 'process' from '/'

Steps to reproduce, variant two

  1. Put the above files in a directory and cd into it.
  2. npm install
  3. mv node_modules _node_modules
  4. ln -s _node_modules/ node_modules
  5. brunch b

Output:

20 Dec 10:17:50 - error: Processing of _node_modules/process/browser.js failed. Cannot find module 'package.json' 
20 Dec 10:17:50 - info: compiled 2 files into app.js in 634 ms

Why symlink?

The idea was to have the following deploy script:

  1. git reset the repo
  2. Has package.json changed, or is ../node_modules missing?
    1. npm install
    2. mv node_modules ..
  3. ln -s ../node_modules node_modules
  4. brunch build --production

This way, I don’t have to npm install on every single deploy, which speeds up deploys quite a bit.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
shvaikaleshcommented, Dec 27, 2016

Does that use npm? Or does it use yarn if available?

It does. npm i -S hellyeahllc/brunch#yarn

0reactions
denysdovhancommented, Jan 23, 2017

Current pattern is /(^bower_components|node_modules|vendor)\// and it fixes this issue, so I close this as fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Having project_name/node_modules as a symlink?
The "duplicated dependencies" is a huge concern, because the files take up quite a lot of space even for very small projects, and...
Read more >
Why isn't the npm link command working? | Benjamin W Fox
Running npm link creates a symlink (or 'symbolic link') from your global node_modules folder to the my-package directory (where the command was ...
Read more >
npm-link
First, npm link in a package folder with no arguments will create a symlink in the global folder {prefix}/lib/node_modules/<package> that links to the...
Read more >
Npm link set up advice and troubleshooting - Code Buckets
When you use npm link, it sets up a symlink in your global node_modules folder which points back to your local environment.
Read more >
Problems on symlinking from a synced folder - Google Groups
EPROTO: protocol error, symlink '../acorn/bin/acorn' -> '/var/www/html/project/node_modules/.bin/acorn'. npm ERR! npm ERR! If you need help, you may report ...
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