Not able to launch Karma test: Uncaught Error: Module name "http" has not been loaded
Not able to launch Karma test: Uncaught Error: Module name "http" has not been loaded
我在 运行 业力测试
时收到此错误
Uncaught Error: Module name "http" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
at C:/projects/xxx_Phase_II/xxx/xxx-web/src/test/javascript/config/node_modules/requirejs/require.js:140
它植根于 dev-rest-proxy.js
第一行
var http = require('http');
我的 package.json
看起来像这样
{
"name": "myApp",
"description": "myApp Web UI",
"engines": {
"node": ">= 0.8.4"
},
"dependencies": {
"express": ">=3.x",
"karma": ">=0.13",
"request": ">=2.27.0"
},
"scripts": {
"pretest": "start node server.js",
"karma": "node ./node_modules/karma/bin/karma start ./karma.unit.conf.js",
"test": "node ./node_modules/karma/bin/karma start ./karma.e2e.conf.js"
},
"version": "0.1.0",
"devDependencies": {
"jasmine-core": "^2.4.1",
"jasmine-jquery": "^2.1.1",
"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.3.7",
"karma-requirejs": "^0.2.5",
"dev-rest-proxy": "^0.3.0"
}
}
我的 karma.unit.config.js
看起来像这样:
module.exports = function (config) {
config.set({
basePath: '../../../',
frameworks: ['jasmine', 'requirejs'],
files: files: [
'app/vendor/**/**/*.js'
]
reporters: ['progress'],
junitReporter: {
outputFile: 'test_out/unit.xml',
suite: 'unit'
},
port: 9876,
runnerPort: 9100,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
});
};
我修好了。我在 files
中给出的模式过于宽泛,因为它包括像 dev-rest-proxy.js
这样的节点服务器端文件。我的 karma.unit.config.js
有:
files: [
'app/vendor/**/**/*.js'
],
所以它会包含这个文件:
app/vendor/node_modules/dev-rest-proxy/dev-rest-proxy.js
dev-rest-proxy
是后端节点的东西,不应该加载到浏览器上,即它指的是 code/module,就像 'http' 一样,它纯粹是服务器端脚本。
我错过的重要线索是错误消息本身:
Module name “http” has not been loaded
http
是节点的服务器端模块。
我在 运行 业力测试
时收到此错误Uncaught Error: Module name "http" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
at C:/projects/xxx_Phase_II/xxx/xxx-web/src/test/javascript/config/node_modules/requirejs/require.js:140
它植根于 dev-rest-proxy.js
第一行
var http = require('http');
我的 package.json
看起来像这样
{
"name": "myApp",
"description": "myApp Web UI",
"engines": {
"node": ">= 0.8.4"
},
"dependencies": {
"express": ">=3.x",
"karma": ">=0.13",
"request": ">=2.27.0"
},
"scripts": {
"pretest": "start node server.js",
"karma": "node ./node_modules/karma/bin/karma start ./karma.unit.conf.js",
"test": "node ./node_modules/karma/bin/karma start ./karma.e2e.conf.js"
},
"version": "0.1.0",
"devDependencies": {
"jasmine-core": "^2.4.1",
"jasmine-jquery": "^2.1.1",
"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.3.7",
"karma-requirejs": "^0.2.5",
"dev-rest-proxy": "^0.3.0"
}
}
我的 karma.unit.config.js
看起来像这样:
module.exports = function (config) {
config.set({
basePath: '../../../',
frameworks: ['jasmine', 'requirejs'],
files: files: [
'app/vendor/**/**/*.js'
]
reporters: ['progress'],
junitReporter: {
outputFile: 'test_out/unit.xml',
suite: 'unit'
},
port: 9876,
runnerPort: 9100,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
});
};
我修好了。我在 files
中给出的模式过于宽泛,因为它包括像 dev-rest-proxy.js
这样的节点服务器端文件。我的 karma.unit.config.js
有:
files: [
'app/vendor/**/**/*.js'
],
所以它会包含这个文件:
app/vendor/node_modules/dev-rest-proxy/dev-rest-proxy.js
dev-rest-proxy
是后端节点的东西,不应该加载到浏览器上,即它指的是 code/module,就像 'http' 一样,它纯粹是服务器端脚本。
我错过的重要线索是错误消息本身:
Module name “http” has not been loaded
http
是节点的服务器端模块。