致命错误:无法找到本地grunt.在windows7专业版上

"Fatal error: Unable to find local grunt." on windows7 professional

本文关键字:grunt windows7 专业版 致命错误      更新时间:2023-09-26

如果我想开始grunt,我得到以下消息:

c:'repositories'kunde_1'themes-projekt_1'projekt_1-responsive'source>grunt
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

当运行grunt时,您将看到:

C:'Users'dev_user>npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/findup-sync
npm http 304 https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/abbrev
npm http 304 https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/sigmund
C:'Users'dev_user'AppData'Roaming'npm'grunt -> C:'Users'dev_user'AppData'Roaming'npm'node_modules'grunt-cli'bin'grunt
grunt-cli@0.1.13 C:'Users'dev_user'AppData'Roaming'npm'node_modules'grunt-cli
+-- nopt@1.0.10 (abbrev@1.0.7)
+-- resolve@0.3.1
+-- findup-sync@0.1.3 (lodash@2.4.2, glob@3.2.11)

在用户目录中输入grunt:

C:'Users'dev_user>grunt
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

但是当我进入项目目录时,出现了相同的消息!

操作系统:windows 7 Professional
NPM -version: 1.3.5
Node——version: v0.10.15

C:'Users'dev_user>npm ls -g
C:'Users'dev_user'AppData'Roaming'npm
+-- coffee-script@1.9.3
+-- grunt-cli@0.1.13
  +-- findup-sync@0.1.3
  ¦ +-- glob@3.2.11
  ¦ ¦ +-- inherits@2.0.1
  ¦ ¦ +-- minimatch@0.3.0
  ¦ ¦   +-- lru-cache@2.6.5
  ¦ ¦   +-- sigmund@1.0.1
  ¦ +-- lodash@2.4.2
  +-- nopt@1.0.10
  ¦ +-- abbrev@1.0.7
  +-- resolve@0.3.1

我设置的环境变量:

变量名:grunt路径:C:'Users'dev_user'AppData'Roaming'npm'grunt然后推出了新的电脑

有谁知道为什么消息致命错误:无法找到本地grunt。来吗?

安装grunt-cli不安装Grunt任务运行器。grunt-cli是命令行接口,允许在同一台机器上同时安装多个版本的Grunt。

要安装grunt,您需要通过以下命令全局安装它:

npm install -g grunt

或本地通过以下命令:

npm install grunt

您可以在官方文档

中阅读grunt-cli

来自@Matthew Bakaitis的注释:

不建议全局安装grunt

这是一个很好的做法,因为grunt-cli首先加载全局版本(如果我没记错的话)。如果一个项目需要一个特定版本的grunt,那么全局安装会破坏这一点。此外,如果您的构建依赖grunt,为什么不将其作为依赖项安装并在package.json中列出呢?如果您没有在package.json中添加依赖项,那么其他开发人员或目标系统将全局安装grunt,这是一个很大的假设。考虑到grunt的使用情况,我想不出有多少情况下全局安装会更好。

解决我的问题。就我而言,我的一位同事找到了解决方案。我安装了两个版本的NodeJS,一个旧的1.0.35版本和当前的1.2.7版本。在Windows卸载程序中,只有一个版本可见!在我卸载了那个版本和所有目录后,即旧版本和新版本被删除后,当前版本被矛盾安装,因为我可以命令should npm install调用。之后,我可以很容易地发出呼叫,它工作正常。