【问题标题】:Error when typing cmd grunt jshint.输入 cmd grunt jshint 时出错。
【发布时间】:2017-10-18 19:39:56
【问题描述】:

我目前正在与 Steve Foote 一起学习如何编程。我使用 ubuntu 作为操作系统。我已经安装了 Node.js,安装了 grunt 命令行,并将 npm install 安装到正确的文件夹中。 我注意到一个问题,当我在指定文件夹上运行节点时,它不会运行我拥有的 js 文件。我什至去了带有 js 文件的文件夹,但它没有工作。然后我尝试了 node values.js 但没有任何结果。

这是我的 package.json 文件代码:

   {
      "name": "kittenbook",
      "version": "0.0.1",
      "devDependencies": {
        "grunt": "^0.4.5",
        "grunt-contrib-concat": "~0.3.0",
        "grunt-contrib-copy": "~0.5.0",
        "grunt-contrib-jshint": "~0.6.3"
      }
   }

这是 Gruntfile.js

module.exports = function(grunt) {
//Project Configuiration
grunt.initConfig({
   /*
    * We will configuire our tasks here
   */
   concat: {
      release: {
          src:['js/values.js', 'js/prompt.js'],
          dest: 'release/main.js'
      }
   },

  copy: {
     release{
         src: 'manifest.json',
         dest: 'release/manifest.json'
     }
  },

  jshint: {
     files: ['js/values.js', 'js/prompt.js']
  } 

 });

 //We will load our plugins here
 grunt.loadNpmTasks('grunt-contrib-concat');
 grunt.loadNpmTasks('grunt-contrib-copy');
 grunt.loadNpmTasks('grunt-contrib-jshint');

 //We will register our tasks here
 grunt.registerTask('default', ['jshint', 'concat', 'copy']);
};

很抱歉,如果这里的格式不好,它真的全部排在文本文件上。

当我输入 grunt jshint 时,会出现一个警告:

Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token {
Warning: Task "jshint" not found. Use --force to continue.

Aborted due to warnings.

【问题讨论】:

  • 您预计会发生什么?意思是,你希望运行什么命令,你希望它的输出是什么?
  • 当我输入命令节点时,会出现提示。但它应该运行我拥有的javafiles。当我在提示中键入 prompt.js 时,它给了我一个错误:'ReferenceError: prompt is not defined'

标签: javascript json node.js gruntjs


【解决方案1】:

您的 grunt.initConfig 对象中缺少一个冒号 (:)。

copy: { release{ /*<--Missing colon in between "release" and the opening bracket {*/ src: 'manifest.json', dest: 'release/manifest.json' } },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    相关资源
    最近更新 更多