尝试加载使用browserify-shim填充的模块时,业力-browserify引发错误 [英] karma-browserify throws error when trying to load modules shimmed with browserify-shim

查看:113
本文介绍了尝试加载使用browserify-shim填充的模块时,业力-browserify引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道也有类似的问题,但是没有一个能解决我的问题.

I know there were similar questions but none of them solved my problem.

当我运行karma test时,它每次尝试加载模块时都会引发以下错误,该错误是被browserify-shim填充的:

When I run karma test it throws the following error, every time it tries to load a module, that was shimmed with browserify-shim:

TypeError: 'undefined' is not an object (evaluating 'module.exports = ex')
  at /tmp/8ff1e03f7ba1f9c70ee4192510d267a2.browserify:3855:0 <- lib/underscore/underscore.js:1421:0

我的karma.conf.js如下:

My karma.conf.js is the following:

module.exports = function(karma) {
    karma.set({

        frameworks: [ 'jasmine', 'browserify' ],

        files: [
            'test/spec/**/*Spec.js'
        ],

        reporters: [ 'dots' ],

        preprocessors: {
            'test/spec/**/*Spec.js': [ 'browserify' ]
        },

        browsers: [ 'PhantomJS' ],

        logLevel: 'LOG_DEBUG',

        singleRun: true,
        autoWatch: false,

        // browserify configuration
        browserify: {
            debug: true,
            transform: [ 'reactify', 'browserify-shim' ]
        }
    });
};

这是我的package.json文件的相关部分:

And here is the relevant part of my package.json file:

...
  "browser": {
    "underscore": "./lib/underscore/underscore.js",
    "jquery": "./lib/jquery/dist/jquery.js",
    "typeahead": "./lib/bootstrap3-typeahead/bootstrap3-typeahead.js",
    "bootstrap": "./lib/bootstrap/dist/js/bootstrap.js",
    "q": "./lib/q/q.js"
  },
  "browserify-shim": {
    "underscore": "_",
    "jquery": "jQuery",
    "typeahead": {
      "depends": [
        "jquery"
      ]
    }
  },
  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
....

任何想法会导致问题吗?

Any idea what can caus the problem?

推荐答案

我遇到了同样的问题,并且遇到了

I had the same problem and have resolved it by removing the browserify-shim transform from karma configuration file, since it is already declared as a transform on package.json file.

希望有帮助.

这篇关于尝试加载使用browserify-shim填充的模块时,业力-browserify引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆