未捕获的ReferenceError:未定义define

时间:2016-05-02 16:08:39

标签: javascript google-chrome grails jasmine karma-runner

感谢您提供的任何帮助。我有一个Grails项目,我正在尝试安装Karma。但是,当我跑     ./gradlew build

我收到以下错误:

[x-10-105-56-234]SENG5199-twtr  (BRANCH1) $ ./gradlew check
:bowerInit UP-TO-DATE
:nodeSetup UP-TO-DATE
:bowerDependencies UP-TO-DATE
:bowerConfig
:bowerComponents UP-TO-DATE
:bowerInstall UP-TO-DATE
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:karmaInit UP-TO-DATE
:karmaDependencies UP-TO-DATE
:karmaGenerateConfig UP-TO-DATE
:karmaRun
Chrome 50.0.2661 (Mac OS X 10.11.4) ERROR
Uncaught ReferenceError: define is not defined at /private/tmp/SENG5199-twtr/grails-app/assets/bower/jquery/src/jquery.js:1
:karmaRun FAILED

FAILURE: Build failed with an exception.


* What went wrong:
Execution failed for task ':karmaRun'.
> Process 'command '/Users/me/.gradle/nodejs/node-v4.2.3-darwin-x64/bin/node'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or     --debug option to get more log output.
BUILD FAILED
Total time: 18.894 secs

的build.gradle

buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
        classpath "org.grails.plugins:hibernate:4.3.10.5"
    }
}

plugins {
    id 'io.spring.dependency-management' version '0.5.4.RELEASE'
    id 'com.craigburke.bower-installer' version '2.5.1'
    id 'com.craigburke.karma' version '1.4.3'
}

version "0.1"
group "seng5199.twtr"

apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"

apply plugin: 'eclipse'
apply plugin: 'idea'

ext {
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = project.gradleWrapperVersion
}

assets {
    minifyJs = true
    minifyCss = true
}

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false
}

dependencies {
    assets "com.craigburke.angular:angular-template-asset-pipeline:2.2.7"

    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile 'org.grails.plugins:spring-security-rest:2.0.0.M2'
    compile 'org.grails.plugins:spring-security-rest-gorm:2.0.0.M2'


    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"

    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate"
    compile "org.hibernate:hibernate-ehcache"

    console "org.grails:grails-console"
    // profile "org.grails.profiles:web:3.1.3"
    runtime "org.grails.plugins:asset-pipeline"
    runtime "com.h2database:h2"

    testCompile "org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC2"
    testCompile "org.grails:grails-plugin-testing"

    testCompile("org.grails.plugins:geb") {
        exclude group: "org.seleniumhq.selenium"
    }

    testCompile "com.google.guava:guava:18.0"

    testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:2.53.0"
    testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:2.53.0"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}

bower {

    'jquery'('2.2.x'){
        source 'dist/jquery.js'
    }

    'bootstrap'('3.3.x') {
        source 'dist/css/bootstrap.css' >> 'css/'
        source 'dist/css/bootstrap-theme.css' >> 'css/'
        source 'dist/fonts/**' >> 'fonts/'
        source 'dist/js/bootstrap.js'
        //excludes 'jquery'
    }

    'angular'('1.5.x') {
        source 'angular.js'
        source 'angular-csp.css'
    }

    'angular-mocks'('1.5.x') {
        source 'angular-mocks.js'
    }

    'angular-route'('1.5.x') {
        source 'angular-route.js'
    }

    'angular-resource'('1.5.x') {
        source 'angular-resource.js'
    }

    'angular-bootstrap'('1.3.x') {
        source 'ui-bootstrap.js'
        source 'ui-bootstrap-tpls.js'
        source 'ui-bootstrap-csp.css' >> 'css/'
    }

    'angular-webstorage'() {
        source 'angular-webstorage.js'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = gradleWrapperVersion
}

karma {
    profile 'default'
    colors = true

    browsers = ['Chrome']
    frameworks = ['jasmine']
    reporters = ['junit', 'progress', 'coverage']
    preprocessors = [
            '**/grails-app/assets/javascripts/app/**/*.js': ['coverage']
    ]

    profile('default') {
        libraryBases = ['**/grails-app/assets/bower/']
        libraryFiles = ['**/jquery.js', '**/angular.js', '**/!(jquery|angular).js']

        sourceBases = ['**/grails-app/assets/javascripts/']
        sourceFiles = ['application.js', 'app/**/*.js']

        testBases = ['**/src/test/javascript/']
        testFiles = ['*.js']
    }
}

compileJava.dependsOn bowerInstall
clean.dependsOn bowerClean

构建/ karma.conf.js

module.exports = function(config) { config.set({
    "basePath": "/private/tmp/SENG5199-twtr",
    "colors": true,
    "logLevel": "ERROR",
    "files": [
        "**/grails-app/assets/bower/**/jquery.js",
        "**/grails-app/assets/bower/**/angular.js",
        "**/grails-app/assets/bower/**/!(jquery|angular).js",
        "**/grails-app/assets/javascripts/application.js",
        "**/grails-app/assets/javascripts/app/**/*.js",
        "**/src/test/javascript/*.js"
    ],
    "browsers": [
        "Chrome"
    ],
    "frameworks": [
        "jasmine"
    ],
    "reporters": [
        "junit",
        "progress",
        "coverage"
    ],
    "preprocessors": {
        "**/grails-app/assets/javascripts/app/**/*.js": [
            "coverage"
        ]
    },
    "exclude": [

    ]
}) };

感谢您的反馈。

1 个答案:

答案 0 :(得分:1)

如果您使用的是define,则还需要将requireJS作为依赖项。