当我运行grunt
orgrunt -v
时,出现错误:
grunt-cli: The grunt command line interface (v1.2.0)
Fatal error: Unable to find local grunt.
If you're seeing this message, 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(我是使用 npm 的初学者)
npm install -g grunt
npm install grunt
npm install grunt --save-dev
安装新/旧软件包后,我也运行npm install
了几次。
这是我的package.json
依赖项:
"dependencies": {
"@webcomponents/webcomponentsjs": "^2.1.0",
"babel-plugin-transform-es2015-modules-amd": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babelify": "^8.0.0",
"browserify": "^16.2.2",
"npm-check-updates": "^2.14.2",
"requirejs": "^2.3.6",
"rollup-plugin-node-resolve": "^3.3.0"
},
"devDependencies": {
"autoprefixer": "^9.1.3",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"cssnext": "^1.8.4",
"grunt": "^1.0.3",
"grunt-babel": "^7.0.0",
"grunt-browserify": "^5.3.0",
"grunt-concurrent": "^2.3.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-csslint": "^2.0.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-postcss": "^0.9.0",
"grunt-serve": "^0.1.6",
"load-grunt-tasks": "^4.0.0",
"material-components-web": "^0.39.1",
"pixrem": "^4.0.1",
"postcss-cssnext": "^3.1.0",
"precss": "^3.1.2",
"webpack-cli": "^3.1.2"
}
是否存在导致这种情况的差异?我在 StackOverflow 上引用了以下GitHub 线程和其他答案,并遵循了他们的建议,但不知所措。
在执行此命令之前,我没有收到此错误,如这篇关于使用 Browserify/Babel 输出多个包的文章中所示:
npm install grunt grunt-cli grunt-browserify babelify babel-preset-es2015 --save-dev
我不确定为什么会破坏事情。npm 不会自动安装最新的包吗?我应该尝试单独卸载这些软件包吗?
当我运行时npm install grunt
,我不断看到这些警告:
npm WARN grunt-serve@0.1.6 requires a peer of grunt@~0.4.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-cli@3.1.2 requires a peer of webpack@^4.x.x but none is installed. You must install peer dependencies yourself.
这可能与问题有关吗?
谢谢