[英]Angular2 + webpack Uncaught ReferenceError: System is not defined
I've got the same issue like here: Why webpack bundled as 'System.register' 我有同样的问题: 为什么webpack捆绑为'System.register'
I've build bundle.js with webpack and I am getting error: 我用webpack构建了bundle.js,我收到了错误:
Uncaught ReferenceError: System is not defined
未捕获的ReferenceError:未定义系统
my bundle.js inlcudes: 我的bundle.js包括:
System.register(['angular2/platform/browser', './app.component', 'rxjs/Rx'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var browser_1, app_component_1;
return {
setters:[
function (browser_1_1) {
browser_1 = browser_1_1;
},
function (app_component_1_1) {
app_component_1 = app_component_1_1;
},
function (_1) {}],
execute: function() {
//enableProdMode();
browser_1.bootstrap(app_component_1.AppComponent)
.then(function (success) { return console.log("Bootstrap success"); })
.catch(function (error) { return console.log(error); });
}
}
});
I've already changed module to commonjs in tsconfig.json, so it's probably some silly mistake somewhere. 我已经在tsconfig.json中将模块更改为commonjs,所以在某处可能有些愚蠢的错误。 Here is my tsconfig.json
这是我的tsconfig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "commonjs",
"removeComments": true,
"sourceMap": false
},
"exclude": [
"node_modules"
]
}
and webpack.config.js 和webpack.config.js
module.exports = {
entry: "./app/main",
output: {
filename: "bundle.js"
},
resolve: {
extensions: ['', '.js', '.ts']
},
module: {
loaders: [{
test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
}]
}
};
Thanks for any help 谢谢你的帮助
将module
更改为commonjs
的compilerOptions
中的commonjs。
当使用带有Typescript项目的webpack时,如果使用commonjs作为模块,则不应将.ts文件转换为.js文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.