Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local Npm module <> not found. Is it installed? #232

Closed
Melindrea opened this issue Jun 16, 2012 · 24 comments
Closed

Local Npm module <> not found. Is it installed? #232

Melindrea opened this issue Jun 16, 2012 · 24 comments

Comments

@Melindrea
Copy link

So, I've been playing around with grunt. At work everything went splendid, but now that I'm trying to run two of the npm tasks (grunt-shell and grunt-contrib), I'm running into an issue.

When I run grunt, it pops up 'Local Npm module "grunt-shell" not found. Is it installed? Local Npm module "grunt-contrib" not found. Is it installed?'. Both are, both globally with npm and locally with npm, at least I see them when I run npm list both globally and locally.

The other tasks are working fine, and the file is reported to be "lint free".

npm 1.1.25
node 0.6.18
nvm to controll version
Grunt-contrib 0.0.7
grunt-shell 0.1.1

grunt is installed globally, the two tasks are installed both globally and locally.
which grunt-shell/contrib gives: /home/marie/nvm/v0.6.18/bin/grunt-*

So, do you have any idea on what might be going wrong?

@cowboy
Copy link
Member

cowboy commented Jun 16, 2012

When using plugins inside a project's gruntfile, npm module plugins loaded via grunt.loadNpmTasks must be installed locally (in ./node_modules/plugin_name relative to the gruntfile).

Does that help?

@Melindrea
Copy link
Author

Yes, it did. idly annoying that they're not put there when one installs them locally, but that's clearly an npm (or maybe my system...) issue.

I really like this system, btw. Only been using it since Thursday, and already started figuring out how it can be used in some very nice ways. =)

@cowboy
Copy link
Member

cowboy commented Jun 17, 2012

Yeah, I don't really want some automated process modifying the gruntfile, so you'll have to add them yourself!

@cyjake
Copy link

cyjake commented Jul 5, 2012

Why is it required that one should install modules locally? Isn't it possible that there might be several projects which use some module like grunt-less mutually?

@webgefrickel
Copy link

Afaik it is not required per se if your provide the correct path in grunt.loadNpmTasks.
If successfully load globally installed grunt-plugins on my system by including them like this:

grunt.loadNpmTasks('/usr/local/lib/node_modules/grunt-compass');

@cyjake
Copy link

cyjake commented Jul 5, 2012

Yes, I am aware of that. But isn't that a little bit verbose? All I want is npm install grunt-less -g, then all of my projects' grunt config which requires grunt-less will work.

Also, I noticed that there is a function called loadNpmTasksWithRequire (https://github.com/cowboy/grunt/blob/master/lib/grunt/task.js#L311). Why is that kept private?

@cowboy
Copy link
Member

cowboy commented Jul 5, 2012

Npm doesn't provide a mechanism for loading globally-installed modules. Which is good, because you want them to be installed local to your project, anyways.

Imagine a scenario where project A requires v1.0.0 of a plugin, so you install it globally, and everything works great. Then you start work on project B which requires features in v2.0.0 of the same plugin, so you install that globally. When finished with project B, you switch back to project A, run grunt and boom everything explodes because it's now using the wrong version of the plugin.

If you only worked on one project, ever, having everything installed globally would work... but the instant you start to work on multiple projects, it just doesn't scale. So install your project's dependencies locally, and you won't ever run into this problem.

And FWIW, even though you install grunt globally, as of v0.4.0 (coming soon) the global grunt will defer to any locally-installed grunt you may have installed, so in that specific case, you'll get the benefit of both the "global" plus "local" behavior.

@cyjake
Copy link

cyjake commented Jul 6, 2012

Ah, now I understand your intention. I thought npm would provide multiple version support like gem in ruby land. Maybe something like the bundler of ruby will help?

Looking forward to your v0.4.0. Thanks for your patient reply.

@cowboy
Copy link
Member

cowboy commented Jul 6, 2012

@dotnil many people think Npm should handle the multiple version support like gems do, but it doesn't. I'm not sure why, tbh.

@philfreo
Copy link

I'm sure many others will end up with this problem. If you don't have a node_modules folder or package.json file installing grunt-contrib even without the -g flag will make npm search for one of those two things up until it hits your global location. So make that folder or a package.json first.

@alexgorbatchev
Copy link

👎 I find this requirement superficial and restrictive. If I want to have multiple Gruntfiles in nested modules, there's no reason why grunt can't look up the folder and see my tasks in one central location. I have a few dozen modules in my project all of which reuse parent model node_modules folder so that I don't have to have same dependencies installed over and over again everywhere. Trying to setup per module grunt file is proving to be a giant pain because of this "opinionated" restriction.

@alexgorbatchev
Copy link

Found that you can also do this... it's more concise than loadNpmTasks

module.exports = (grunt) ->
  require('grunt-mocha/tasks/mocha')(grunt)

@LeezQ
Copy link

LeezQ commented May 14, 2013

@alexgorbatchev cant't agree anymore.

@LeezQ
Copy link

LeezQ commented May 14, 2013

I think grunt.loadNpmTasks should have support positive node_module dir . like require in nodejs, then I can have same node_modules in parent dir , and I can have own Gruntfile in sub-project .

@patrickkettner
Copy link

I needed to load modules from inside of modules, so I hacked on @sindresorhus' lovely load-grunt-tasks, and made load-grunt-subtasks. I believe it would cover most of the use cases people were looking for here

@cowboy
Copy link
Member

cowboy commented Dec 4, 2013

@patrickkettner if you specify dependency plugins as peerDependencies you shouldn't need to do anything special. See:

https://github.com/gruntjs/grunt-contrib/blob/master/package.json#L36-L63
https://github.com/gruntjs/grunt-contrib/blob/master/tasks/contrib.js#L12-L17

@patrickkettner
Copy link

@cowboy thanks! I am not sure it applies in my exact case.

I have project X that has arbitrary projects foo, bar, and baz, all of which are also used in project Y.

X
├─┬ foo
│ ├── grunt-one
│ ├── grunt-wo
├─┬ bar
│ ├── grunt-threeThistTmeItsPersonal
├─┬ baz
│ ├── grunt-contrib-clean

Where as Y may be structured like

Y
├─┬ foo
│ ├── grunt-one
│ ├── grunt-wo
├─┬ baz
│ ├── grunt-contrib-clean

I wanted a way to share the grunt plugins of foo, bar, and baz in a top level project. Having all of those modules defined in X and Y's own package.json leads to a bit more overhead than i would prefer to have.

@cowboy
Copy link
Member

cowboy commented Dec 4, 2013

Yeah, your use-case is pretty non-standard.

@patrickkettner
Copy link

yep, thanks a ton for reaching out

@peterbraden
Copy link

So if I load a module in grunt, and that module has dependencies, then they won't be loaded? This seems like a pretty broken system, why not just use require?

samccone pushed a commit to samccone/grunt that referenced this issue Jul 24, 2014
@dcleao
Copy link

dcleao commented Sep 19, 2014

Hi @cowboy,
so it's non-standard to want to have the Gruntfile.js not beside the node_modules folder?

project/
 \_ node_modules/
      \_ grunt/
      \_ grunt-contrig-something/
 \_ configs/
      \_ Gruntfile.js
 \_ package.json

Simply, executing, from the project root:

$ grunt -gruntfile "configs/Gruntfile.js"

fails. Amazing.

Is this a way to force people place the "Gruntfile.js" beside "package.json" ?
Or else, we're forced to not use grunt.loadNpmTasks...
Makes me wonder why you even have the "-gruntfile" option.
Funny, also, that in a lot of other places of grunt's code, it does findUp for node_modules.
I'm disappointed.

@shawnholt
Copy link

So the implication is you can't mix a global install of some modules and others locally without explicitly specifying. That wasn't intuitive to me at least....

@flocsy
Copy link

flocsy commented Nov 8, 2016

@webgefrickel it only works with loadTasks instead of loadNpmTasks:
grunt.loadTasks('/usr/local/lib/node_modules/grunt-compass');

@chasepeeler
Copy link

I know this is old, but, anyone just finding this like I did, use load-grunt-tasks as mentioned above, with the requireResolution option set to true:

require('load-grunt-tasks')(grunt,{requireResolution: true});

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

No branches or pull requests