我有這樣的錯誤:StealJS錯誤:跨起源請求不被支持的協議方案
XMLHttpRequest cannot load file:///Users/mshin/workspace/spirent/trinity/trinity-link/public/node_modules/can/view/stache/system.js. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
home.js:在Gruntfile
import can from 'can';
import template from './home.stache!';
export default can.Component.extend({
tag: 'home',
template: template
});
構建配置:
"steal-build": {
default: {
options: {
system: {
config: "package.json!npm",
bundlesPath: "production"
},
buildOptions: {
minify: true,
sourceMaps: true
}
}
}
}
我不知道爲什麼我在生產模式下收到此錯誤消息。在開發環境中,它工作正常。另外,在測試環境上也不錯。我正在和被測試者一起運行QUnit測試。
home_test.js:
import QUnit from 'steal-qunit';
import ViewModel from 'components/home/home';
import can from 'can';
import stache from 'can/view/stache/';
import $ from 'jquery';
var template = can.stache('<home></home>'),
$component;
QUnit.module('home component', {
setup: function() {
$('#trinity-js-tests').html(template());
$component = $('#trinity-js-tests').find('home');
}
});
QUnit.test('title tag', function() {
QUnit.ok($component.find('h1'), 'Page shows title with <h1> tag');
});
QUnit.test('title content', function() {
QUnit.strictEqual($component.find('h1').text(), 'This is homepage.', 'Title is "This is homepage."');
});
但是,如果我改變home.js喜歡這個:
import can from 'can';
export default can.Component.extend({
tag: 'home',
template: can.view('components/home/home.stache)
});
它工作在生產和開發環境很好,但在測試的最後測試案件失敗。
1) QUnit "public/tests/test.html" on PhantomJS 1.9.8/Mac OS X 0.0.0: <a href="http://localhost:3996/public/tests/test.html?__token=k8l88m"></a> home component title content Title is "This is homepage.":
Error: Expected This is homepage. but was
at http://localhost:3996/public/tests/test.html?__token=k8l88m:1340
at http://localhost:3996/public/tests/test.html?__token=k8l88m:1907
at :33
at http://localhost:3996/public/tests/test.html?__token=k8l88m:895
at http://localhost:3996/public/tests/test.html?__token=k8l88m:1024
at process (http://localhost:3996/public/tests/test.html?__token=k8l88m:583)
at begin (http://localhost:3996/public/tests/test.html?__token=k8l88m:628)
at http://localhost:3996/public/tests/test.html?__token=k8l88m:644
那麼,如何我可以加載在生產模式下的「http」協議文件? –
我不知道爲什麼'can/view/stache/system.js'加載file://協議,而不是應用程序的dirname ..... –
我找到原因和解決方案。我沒有在主文件中導入'can/view/stache/system.js'文件。我雖然'can/view/stache/stache.js'文件導入了所有的東西,但它沒有。所以我在主JavaScript文件中添加了'import'can/view/stache/system';'。謝謝。 –