node.js grunt - 得到“未找到本地 Npm 模块“xxx”。是否已安装?这是什么原因造成的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23767122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
grunt - getting "Local Npm module "xxx" not found. Is it installed?" What's causing this?
提问by u353
I just received a copy of a grunt package to work on, but I'm new to grunt and am having trouble finding answers to a few things. The biggest issue is not knowing where the errors below are coming from - can someone tell me where this is coming from? Both of these files are in the same directory.
我刚刚收到一份需要处理的 grunt 软件包的副本,但我是 grunt 新手,并且无法找到一些问题的答案。最大的问题是不知道下面的错误来自哪里 - 有人能告诉我这是从哪里来的吗?这两个文件都在同一个目录下。
$ grunt
>> Local Npm module "grunt-contrib-clean" not found. Is it installed?
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-contrib-cssmin" not found. Is it installed?
>> Local Npm module "grunt-contrib-handlebars" not found. Is it installed?
>> Local Npm module "grunt-contrib-jshint" not found. Is it installed?
>> Local Npm module "grunt-contrib-qunit" not found. Is it installed?
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?
>> Local Npm module "grunt-preprocess" not found. Is it installed?
>> Local Npm module "grunt-wrap" not found. Is it installed?
>> Local Npm module "grunt-debug-task" not found. Is it installed?
Warning: Task "clean" not found. Use --force to continue.
Aborted due to warning.
$
And here is my package.json:
这是我的 package.json:
{
"name": "baked-widget",
"srcDirectory": "./src",
"srcJavascript": "./src/js",
"srcCss": "./src/css",
"srcData": "./src/data",
"testDirectory": "./test",
"tgtDirectory": "./build",
"installDirectory": "../com/public/widgets",
"version": "4.2.0",
"devDependencies": {
"grunt": "~0.4",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-cssmin": "~0.9.0",
"grunt-contrib-handlebars": "~0.6",
"grunt-contrib-jshint": "~0.8",
"grunt-contrib-uglify": "~0.3",
"grunt-contrib-qunit": "~0.4",
"grunt-contrib-watch": "~0.5",
"grunt-preprocess": "~4.0",
"grunt-wrap": "~0.3",
"grunt-debug-task": "~0.1.4"
}
}
回答by zishe
You probably haven't installed necessary packages locally. Try npm install(sudo npm install) to make sure you did that.
您可能没有在本地安装必要的软件包。尝试npm install( sudo npm install) 以确保您做到了。
回答by wranvaud
If the accepted answer doesn't work AND you have a correct package.jsonfile, you can:
如果接受的答案不起作用并且您有正确的package.json文件,您可以:
delete the
node_modulesfolder (or back it up somewhere)and then run
npm install
删除
node_modules文件夹(或将其备份到某处)然后运行
npm install
in order to get a fresh start.
为了重新开始。
回答by Eduard Streltsov
You have to tell grunt where to find node_modules. My Gruntfile starts with:
你必须告诉 grunt 在哪里可以找到 node_modules。我的 Gruntfile 开始于:
module.exports = function (grunt) {
// Tell grunt where to find node_modules
grunt.file.setBase('../../../../../');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-hub');
In my case, node_modules folder is 5 levels upper (look at setBase method) than Gruntfile.
就我而言,node_modules 文件夹比 Gruntfile 高 5 级(查看 setBase 方法)。

