gpt4 book ai didi

node.js - grunt 安装时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-03 22:42:50 24 4
gpt4 key购买 nike

我按照 grunt site 上的文档进行操作。执行 sudo 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/findup-sync
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/findup-sync
npm http 304 https://registry.npmjs.org/nopt
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/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund/-/sigmund-1.0.0.tgz
npm http 200 https://registry.npmjs.org/sigmund/-/sigmund-1.0.0.tgz
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli@0.1.11 /usr/local/lib/node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21)

此后,当我执行grunt时,我收到此消息

    grunt-cli: The grunt command line interface. (v0.1.11)

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

此后我也关注了this link解决我的问题,但我仍然遇到上面相同的错误。

更新

Gruntfile.js

    module.exports = function () {
grunt.initConfig({
min: {
dist: {
src: 'file-one.js',
dest: 'file-one.min.js'
}
}
});
}

package.json 文件

    {
"name": "grunt",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.1.11",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-uglify": "~0.2.2"
}
}

最佳答案

您已将 grunt-cli 安装为全局包,但还需要在本地安装 grunt。 grunt-cli 包安装一个全局命令行工具,但该命令行工具只是尝试加载本地安装的 grunt 模块。这样做是为了允许人们为不同的项目拥有多个版本的 grunt,您需要将 grunt 本身作为本地包安装在您正在处理的项目中。

从您链接到的页面:

Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.

因此,您需要将 grunt 作为 package.json 文件中的本地依赖项,就像任何其他模块一样,您不会在其中列出 grunt-cli .

关于node.js - grunt 安装时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20586164/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com