SystemJS:为什么在导入jquery时出现错误jquery_1.default不是函数 [英] SystemJS: Why am getting error jquery_1.default is not a function when importing jquery
问题描述
我已经通过jspm安装基础安装了基础,然后导入了基础 和jQuery.
I have installed foundation via jspm install foundation, then import foundation and jquery.
我遇到的问题是,如果我通过import $ as 'jquery'
导入jquery,则会收到错误jquery_1.默认不是函数.如果我通过import * as $ from jquery
导入jquery,它会按预期运行
The problem I am having is that if I import jquery via import $ as 'jquery'
I get the error jquery_1.default is not a function. If I import jquery via import * as $ from jquery
it works as expected
我正在调用$(document).foundation();
来初始化基础javascript组件.以下是我的main.ts
I am calling $(document).foundation();
to initialize foundations javascript components. Below is my main.ts
import 'foundation'
import $ from 'jquery';
import {Aurelia} from 'aurelia-framework';
export function configure(aurelia: Aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(a => a.setRoot())
.then(a => {
// Initialize framework
$(document).foundation();
});
}
其余代码只是默认导航到一个简单的页面,该页面包含带有下拉列表的基础导航栏
The rest of the code is just default navigation to a simple page that contains a foundation nav bar with dropdown list
注意:即使jquery被列为dep,我也必须显式安装jquery.
Note: I also had to explicitly install jquery even though jquery is listed as a dep.
我对基础6进行了原始覆盖,显然做错了什么,但当时似乎可行.但是,我之后发现,在安装引导程序时,将jquery放在github:components中,这似乎可以做到,因此不必显式安装jquery.因此,当时一切似乎都很好.
I made the original override for foundation 6, clearly did something wrong but it seemed to be working at the time. However, I have since found out that when bootstrap was installed it put jquery in github:components and that seemed make it so jquery did not have to explicitly be installed. So at the time all seemed fine.
要进行复制,只需使用aurelia骨架并添加带有基础控件的页面,然后如上所述添加$(document).foundation()
To reproduce just use the aurelia skeleton and add a page with a foundation control, adding the $(document).foundation() as above
推荐答案
如果您在tsconfig中使用打字稿集module = system:
If you are using typescript set module=system in your tsconfig:
{
"compilerOptions": {
"module": "system",
"target": "es6",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": [
"node_modules",
"jspm_packages"
]
}
这篇关于SystemJS:为什么在导入jquery时出现错误jquery_1.default不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!