Problems if `node_modules/` is a symlink
See original GitHub issueDescription
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
- Brunch: 2.9.1
- Node: 6.9.1
- NPM: 3.10.8
- 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
- Put the above files in a directory and
cd
into it. npm install
mv node_modules ../node_modules
ln -s ../node_modules/ node_modules
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
- Put the above files in a directory and
cd
into it. npm install
mv node_modules _node_modules
ln -s _node_modules/ node_modules
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:
- git reset the repo
- Has package.json changed, or is
../node_modules
missing?npm install
mv node_modules ..
ln -s ../node_modules node_modules
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:
- Created 7 years ago
- Comments:12 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It does.
npm i -S hellyeahllc/brunch#yarn
Current pattern is
/(^bower_components|node_modules|vendor)\//
and it fixes this issue, so I close this as fixed.