Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Cannot find module 'underscore' when running gulp production #87

Closed
TexRx opened this issue Jan 26, 2015 · 7 comments
Closed

Cannot find module 'underscore' when running gulp production #87

TexRx opened this issue Jan 26, 2015 · 7 comments

Comments

@TexRx
Copy link

TexRx commented Jan 26, 2015

I get the following error when running the production build

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Cannot find module 'underscore' from '/Users/Chris/Projects/gulp-starter'

Do you not get this error when you run the production gulp task?

@ieugen
Copy link

ieugen commented Jan 26, 2015

maybe you have corrupted modules? try removing node_modules folder and do npm install again

@TexRx
Copy link
Author

TexRx commented Jan 26, 2015

After a bit of testing, I determined that this error occurs if I do not have underscore installed as node_module on it's own. If I perform a checkout of this repo, then immediately run npm install, followed by gulp production, the error occurs. It seems very unlikely that these two steps would result in corrupt modules (I also ran npm cache clean before installing this repo). If I run npm install -D underscore, and then run gulp production, the project builds with no errors. On the other hand, if I do not install underscore as it's own module, but instead replace this line in the config.js:

require: ['jquery', 'underscore']

with:

require: ['jquery', 'backbone/node_modules/underscore']

the build completes successfully.

So, am I doing something else wrong with regard to the loading of underscore? Because, for me, it appears that I either need to have underscore installed as it's own module (e.g., do not rely on underscore within backbone module dependencies), or I have to explicitly specify the path to underscore within the backbone dependencies, when specifying the require-ed assets.

I referenced this during my troubleshooting: https://github.com/substack/node-browserify#brequirefile-opts

I should also note that it appears that listing underscore in the browser section of package.json makes no difference. I removed the underscore reference from package.json, and also tried every variation of the backbone > underscore reference that I could think of, and it made no difference. Additionally, I shim-ed underscore in the browserify-shim section, also to no avail.

@greypants
Copy link
Contributor

Yeah, I saw this happen to a friend at work, but I couldn't replicate it on my machine. Might have something to do with minor version differences. I'll definitely look into it.

Your require: ['jquery', 'backbone/node_modules/underscore'] solution seems like a good one to me. That whole backbone underscore mess is only in this repo to call out a weird edge case where if you listed underscore as a normal dependency, you'd end up with two copies of underscore in your compiled bundle since Backbone is weird and comes with it.

@TexRx
Copy link
Author

TexRx commented Jan 27, 2015

Thanks for the reply. I've run my starter kit (which borrows liberally from your examples here - thanks!!!) on several Macs and Windows machines, and everything is cool as long as I use backbone/node_modules/underscore in the require param array, so I'm going to stick with that for now. The main thing is that I know that it works. Thanks again for all your efforts putting your repo together. It has been immensely helpful.

@greypants
Copy link
Contributor

👍

@greypants
Copy link
Contributor

Was able to reproduce it after upgrading node and npm, killing my node_modules folder and running npm cache clean. Pushed up the fix you suggested with a note linking to this issue. Thanks!

Eventually I need to remove that backbone/underscore example. I think it's more confusing than helpful at this point. Maybe move a note about that edge case into the wiki instead.

greypants added a commit that referenced this issue Jan 27, 2015
domtra added a commit to bleech/gulp-starter that referenced this issue Mar 5, 2015
* upstream/master: (39 commits)
  Remove unused require in watch.js
  Update comment about watchify bug
  Minor grammatical fix in page.js comments
  Update README.md
  Remove unused folder/files
  Add missing semicolons
  Update Readme w/ Karma info
  Move tests to __test__ folder
  Run karma tests as part of production task
  Update karma test example
  Set up karma
  Fix vigetlabs#87
  Add iconFont task to production, make paths relative
  Update README and template w/font
  Update iconFont task with new implementation
  Copy over new icon-font task files
  Icon task cleanup
  Add comment to icons partial and template
  Optimize example svgs
  Update README
  ...
adampash pushed a commit to adampash/gulp-starter that referenced this issue Apr 22, 2015
@alpgumus
Copy link

Got this resolved by fixing the path of underscore in packages.json:

"underscore": "./node_modules/backbone/node_modules/underscore",

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants