admin管理员组文章数量:1314571
I have an Angularjs project and I am using karma to run the tests. I am running into some problems with it, getting this error:
ReferenceError: Can't find variable: require
at http://localhost:9876/base/src/test/bower_ponents/angular-animate/index.js?b8fe1c0a06b723a75c7e596fd8a86d91965f681c:1
Reding into some forums, I was told to use karma browserify, but I am getting this error now:
28 07 2015 22:41:15.573:WARN [preprocess]: Can not load "browserify", it is not registered!
Perhaps you are missing some plugin?
/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:9
throw error('No provider for "' + name + '"!');
^
Error: No provider for "framework:browserify"! (Resolving: framework:browserify)
at error (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:22:68)
at Object.parent.get (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:128:20
at Array.forEach (native)
at Server._start (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:127:21)
at invoke (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Server.start (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:92:18)
at Function.Server.start (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:101:10)
at Object.<anonymous> (/Applications/WebStorm.app/Contents/plugins/js-karma/js_reporter/karma-intellij/lib/intellijServer.js:10:8)
at Module._pile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
Does anybody know what's going on? This is my karma.conf file:
{
// Karma configuration
// Generated on Tue May 19 2015 15:02:17 GMT+0100 (WEST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
plugins: [
'karma-browserify',
'karma-phantomjs-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-spec-reporter'
],
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: [ 'browserify','jasmine'],
// list of files / patterns to load in the browser
files: [
';language=en',
// bower:js
'bower_ponents/jquery/dist/jquery.js',
'bower_ponents/bootstrap-sass/assets/javascripts/bootstrap.js',
'bower_ponents/bootstrap-select/dist/js/bootstrap-select.js',
'bower_ponents/angular/angular.js',
'bower_ponents/angular-animate/angular-animate.js',
'bower_ponents/angular-cookies/angular-cookies.js',
'bower_ponents/angular-touch/angular-touch.js',
'bower_ponents/angular-sanitize/angular-sanitize.js',
'bower_ponents/angular-resource/angular-resource.js',
'bower_ponents/angular-route/angular-route.js',
'bower_ponents/angular-bootstrap/ui-bootstrap-tpls.js',
'bower_ponents/angular-ui-utils/ui-utils.js',
'bower_ponents/angular-ui-map/ui-map.js',
'bower_ponents/angular-http-auth/src/http-auth-interceptor.js',
'bower_ponents/ng-file-upload/ng-file-upload.js',
'bower_ponents/ng-file-upload-shim/ng-file-upload-shim.js',
'bower_ponents/angular-notify/dist/angular-notify.js',
'bower_ponents/moment/moment.js',
'bower_ponents/angular-gettext/dist/angular-gettext.js',
// endbower
'src/app/**/*.js',
'src/app/views/**/*.html',
'src/test/**/*.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors:
preprocessors: {
'**/*.html': ['ng-html2js'],
'**/*.js': [ 'browserify' ]
},
ngHtml2JsPreprocessor: {
// strip this from the file path
stripPrefix: 'src/',
// prepend this to the
// setting this option will create only a single module that contains templates
// from all the files, so you can load them all with module('foo')
moduleName: 'templatesForTest'
},
// test results reporter to use
// possible values: 'dots', 'progress', 'spec'
// available reporters:
reporters: ['spec'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers:
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
}
I have an Angularjs project and I am using karma to run the tests. I am running into some problems with it, getting this error:
ReferenceError: Can't find variable: require
at http://localhost:9876/base/src/test/bower_ponents/angular-animate/index.js?b8fe1c0a06b723a75c7e596fd8a86d91965f681c:1
Reding into some forums, I was told to use karma browserify, but I am getting this error now:
28 07 2015 22:41:15.573:WARN [preprocess]: Can not load "browserify", it is not registered!
Perhaps you are missing some plugin?
/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:9
throw error('No provider for "' + name + '"!');
^
Error: No provider for "framework:browserify"! (Resolving: framework:browserify)
at error (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:22:68)
at Object.parent.get (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:128:20
at Array.forEach (native)
at Server._start (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:127:21)
at invoke (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Server.start (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:92:18)
at Function.Server.start (/Users/brunosiqueira/WebstormProjects/copcast-admin/node_modules/karma/lib/server.js:101:10)
at Object.<anonymous> (/Applications/WebStorm.app/Contents/plugins/js-karma/js_reporter/karma-intellij/lib/intellijServer.js:10:8)
at Module._pile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
Does anybody know what's going on? This is my karma.conf file:
{
// Karma configuration
// Generated on Tue May 19 2015 15:02:17 GMT+0100 (WEST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
plugins: [
'karma-browserify',
'karma-phantomjs-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-spec-reporter'
],
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: [ 'browserify','jasmine'],
// list of files / patterns to load in the browser
files: [
'http://maps.googleapis./maps/api/js?sensor=false&language=en',
// bower:js
'bower_ponents/jquery/dist/jquery.js',
'bower_ponents/bootstrap-sass/assets/javascripts/bootstrap.js',
'bower_ponents/bootstrap-select/dist/js/bootstrap-select.js',
'bower_ponents/angular/angular.js',
'bower_ponents/angular-animate/angular-animate.js',
'bower_ponents/angular-cookies/angular-cookies.js',
'bower_ponents/angular-touch/angular-touch.js',
'bower_ponents/angular-sanitize/angular-sanitize.js',
'bower_ponents/angular-resource/angular-resource.js',
'bower_ponents/angular-route/angular-route.js',
'bower_ponents/angular-bootstrap/ui-bootstrap-tpls.js',
'bower_ponents/angular-ui-utils/ui-utils.js',
'bower_ponents/angular-ui-map/ui-map.js',
'bower_ponents/angular-http-auth/src/http-auth-interceptor.js',
'bower_ponents/ng-file-upload/ng-file-upload.js',
'bower_ponents/ng-file-upload-shim/ng-file-upload-shim.js',
'bower_ponents/angular-notify/dist/angular-notify.js',
'bower_ponents/moment/moment.js',
'bower_ponents/angular-gettext/dist/angular-gettext.js',
// endbower
'src/app/**/*.js',
'src/app/views/**/*.html',
'src/test/**/*.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs/browse/keyword/karma-preprocessor
preprocessors: {
'**/*.html': ['ng-html2js'],
'**/*.js': [ 'browserify' ]
},
ngHtml2JsPreprocessor: {
// strip this from the file path
stripPrefix: 'src/',
// prepend this to the
// setting this option will create only a single module that contains templates
// from all the files, so you can load them all with module('foo')
moduleName: 'templatesForTest'
},
// test results reporter to use
// possible values: 'dots', 'progress', 'spec'
// available reporters: https://npmjs/browse/keyword/karma-reporter
reporters: ['spec'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
}
Share
Improve this question
edited Feb 4, 2016 at 18:58
Ben
57.3k50 gold badges184 silver badges229 bronze badges
asked Jul 28, 2015 at 21:44
Bruno SiqueiraBruno Siqueira
89211 silver badges26 bronze badges
2
- Looking at the basic example I would say you haven't finished configuring browserify like the error message says. npmjs./package/karma-browserify – Matthew Green Commented Jul 28, 2015 at 22:01
-
1
Have you tried
npm install --save-dev karma-browserify
? – mostruash Commented Jul 28, 2015 at 22:03
2 Answers
Reset to default 5I had a similar problem:
Warning: No provider for "framework:mocha"! (Resolving: framework:mocha)
This happened because I didn't include the plugin. Correct config:
...
singleRun: true,
plugins: ['karma-phantomjs-launcher', 'karma-mocha'], // here
frameworks: ['mocha'],
...
Also worth mentioning, you'll need to install the plugin:
npm install karma-mocha --save-dev
https://www.npmjs./package/karma-mocha
After further experimentation, looks like this is the error message delivered when you haven't included the plugin for a specified framework:
...
plugins: ['karma-phantomjs-launcher', 'karma-mocha', 'karma-chai'],
frameworks: ['mocha', 'chai'], // Will require the plugins above
...
I had a few problems with different versions of the libraries. But in the end, I got to make to work like this:
My package.json file:
"karma": "0.12.0",
"karma-html2js-preprocessor": "0.1.0",
"karma-jade-preprocessor": "0.0.11",
"karma-jasmine": "0.1.5",
"karma-ng-html2js-preprocessor": "0.1.2",
"karma-phantomjs-launcher": "0.1.4",
"karma-requirejs": "0.2.1",
"karma-script-launcher": "0.1.0",
"karma-coffee-preprocessor": "0.2.1",
"brfs": "^1.2.0",
"browserify-shim": "~3.8.0",
"karma-browserify": "^3.0.0",
My karma.conf.js file:
// Karma configuration
// Generated on Tue May 19 2015 15:02:17 GMT+0100 (WEST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: [ 'jasmine', 'browserify'],
// list of files / patterns to load in the browser
files: [
'http://maps.googleapis./maps/api/js?sensor=false&language=en',
// bower:js
'bower_ponents/jquery/dist/jquery.js',
'bower_ponents/bootstrap-sass/assets/javascripts/bootstrap.js',
'bower_ponents/bootstrap-select/dist/js/bootstrap-select.js',
'bower_ponents/angular/angular.js',
'bower_ponents/angular-animate/angular-animate.js',
'bower_ponents/angular-cookies/angular-cookies.js',
'bower_ponents/angular-touch/angular-touch.js',
'bower_ponents/angular-sanitize/angular-sanitize.js',
'bower_ponents/angular-resource/angular-resource.js',
'bower_ponents/angular-route/angular-route.js',
'bower_ponents/angular-mocks/angular-mocks.js',
'bower_ponents/angular-bootstrap/ui-bootstrap-tpls.js',
'bower_ponents/angular-ui-utils/ui-utils.js',
'bower_ponents/angular-ui-map/ui-map.js',
'bower_ponents/angular-http-auth/src/http-auth-interceptor.js',
'bower_ponents/ng-file-upload/ng-file-upload.js',
'bower_ponents/ng-file-upload-shim/ng-file-upload-shim.js',
'bower_ponents/angular-notify/dist/angular-notify.js',
'bower_ponents/moment/moment.js',
'bower_ponents/angular-gettext/dist/angular-gettext.js',
// endbower
'src/app/**/*.js',
'src/app/views/**/*.html',
'src/test/**/*.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs/browse/keyword/karma-preprocessor
preprocessors: {
'**/*.html': ['ng-html2js'],
'src/**/*.js': ['browserify']
},
browserify: {
debug: true,
transform: [ 'brfs' ]
},
ngHtml2JsPreprocessor: {
// strip this from the file path
stripPrefix: 'src/',
// prepend this to the
// setting this option will create only a single module that contains templates
// from all the files, so you can load them all with module('foo')
moduleName: 'templatesForTest'
},
// test results reporter to use
// possible values: 'dots', 'progress', 'spec'
// available reporters: https://npmjs/browse/keyword/karma-reporter
reporters: ['spec'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
UPDATE
I recently updated all my libraries to the most recent version and I got this error again. I realized that I was missing the library browserify and watchify themselves. So I installed the two missing libraries and everything worked perfectly.
npm install --save-dev karma-browserify browserify watchify
版权声明:本文标题:javascript - Error: No provider for "framework:browserify"! (Resolving: framework:browserify) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741962651a2407372.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论