Reputation: 14506
I'm a noob in Node.js and trying to use grunt-contrib-concat
to build my javascript library from multiple source files.
I've created a virtual environment, activated it, globally installed grunt
and grunt-cli
, written Gruntfile.js
and package.json
files for my project. To summarize:
$ nodenv NODEENV
$ source NODENV/bin/activate
(NODEENV)$ npm install -g grunt-cli
...
(NODEENV)$ npm install -g grunt
...
(NODEENV)$ cd myproject
(NODEENV)$ ls myproject
Gruntfile.js package.json src test README.md
(NODEENV)$ grunt test
grunt-cli: The grunt command line interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
What I don't understand is why grunt-cli
is telling me that it wants a local per-project version of grunt
if I've already got a globally installed one?
Could you also suggest a way to fix the error?
Upvotes: 2
Views: 12532
Reputation: 1040
If these commands does not work with/without sudo.
npm install -g grunt-cli
npm install grunt
or you are getting error like this
Then follow these steps.
Run npm config list
then check for registry key value.
it can be like:
registry = "https://npm.some.domain.other.than.global.com/"
if you found your case as step 1 then run command
npm config set registry https://registry.npmjs.com/
Done!!
Now you can run
npm install
if your package.json
contains grunt
library name,
otherwise
npm install -g grunt-cli
npm install grunt
It will work now.
Upvotes: 0
Reputation: 123563
It's due to npm's foldering:
- Install it locally if you're going to
require()
it.- Install it globally if you're going to run it on the command line.
The Gruntfile itself depends on require('grunt')
being available, requiring a local install.
$ npm install grunt
And, having grunt(1)
as an available command makes using the tool easier, requiring a global install.
$ npm install -g grunt-cli
To have both, though, it has to be installed in both folders.
Upvotes: 9
Reputation: 2070
That's just the way it works. You always need to:
npm install -g grunt-cli
npm install grunt
Upvotes: 0
Reputation: 2882
Run npm install
from your project directory. For each project, Grunt needs to reside in the npm_modules
directory of your project in order for the project to assert that it is using the correct version of grunt (which may differ from your global version).
Upvotes: 1