【问题标题】:How can I reinstall Grunt in a yeoman project?如何在 yeoman 项目中重新安装 Grunt?
【发布时间】:2015-05-02 10:13:30
【问题描述】:

我的 Grunt 安装出了点问题,我不知道是什么。我正在使用 Yeoman 搭建我的应用程序,但今天我开始遇到许多 Grunt 错误。例如,我现在在运行Grunt Test 时得到以下信息:

Loading "autoprefixer.js" tasks...ERROR
>> Error: Cannot find module 'base64-js'
Loading "connect.js" tasks...ERROR
>> Error: Cannot find module 'cookie-signature'
Loading "imagemin.js" tasks...ERROR
>> Error: Cannot find module './lib/js-yaml.js'
Loading "jshint.js" tasks...ERROR
>> Error: Cannot find module 'jshint'
Loading "uglify.js" tasks...ERROR
>> Error: Cannot find module './source-map/source-map-generator'
Loading "cdnify.js" tasks...ERROR
>> SyntaxError: /Users/Documents/Git/client/node_modules/grunt-google-cdn/node_modules/google-cdn/node_modules/cdnjs-cdn-data/external/cdnjs.json: Unexpected end of input
Loading "grunt-karma.js" tasks...ERROR
>> SyntaxError: /Users/Documents/Git/client/node_modules/karma/node_modules/socket.io/node_modules/engine.io/lib/server.js:390
>> });
>>    
>> Unexpected end of input
Loading "ngmin.js" tasks...ERROR
>> Error: Cannot find module 'estraverse'
Loading "svgmin.js" tasks...ERROR
>> SyntaxError: /Users/Documents/Git/client/node_modules/grunt-svgmin/node_modules/svgo/node_modules/js-yaml/lib/js-yaml/loader.js:950
>> });
>>  ^
>> Unexpected token )
Loading "usemin.js" tasks...ERROR
>> SyntaxError: /Users/Documents/Git/client/node_modules/grunt-usemin/node_modules/lodash/dist/lodash.js:5520
>> });
>> ^
>> Unexpected token }
Loading "css_sprite.js" tasks...ERROR
>> Error: Cannot find module 'async'
Warning: Task "autoprefixer" not found. Use --force to continue.

我更新了 NPM,我尝试更新 Grunt,我尝试安装所有 Grunt 找不到的包。有没有办法对 Grunt 进行 nuke 和 repave 并为这个项目安装一个全新的副本?

【问题讨论】:

    标签: javascript node.js gruntjs npm yeoman


    【解决方案1】:

    您可能已经在您的机器上缓存了部分安装的 npm 包。

    尝试运行npm cache clean

    然后删除安装的项目包: rm -rf node_modules

    然后尝试再运行一次npm install

    【讨论】:

    • 这解决了我的问题 - 在 npm 更新失败后,我对 npm 感到有些奇怪。上述步骤有效,谢谢艾萨克
    【解决方案2】:

    只需按照错误消息...例如你说...

    警告:找不到任务“autoprefixer”。使用 --force 继续。

    尝试安装 grunt-autoprefixer...

    npm install grunt-autoprefixer --save
    

    然后再次运行grunt test...

    您收到其他错误消息...查找丢失的内容...通过 npm 安装它。有时您可能需要在 Google 上搜索正确的包名称...

    【讨论】:

    • 起初我以为我会这样做,但实际上所有“缺失”的软件包都已安装。此外,我尝试运行npm install 重新安装它们,但没有任何改变。
    猜你喜欢
    • 2014-02-09
    • 2017-03-30
    • 2012-12-13
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 1970-01-01
    • 2014-10-04
    相关资源
    最近更新 更多