未捕获ReferenceError:导出未定义并且需要 [英] Uncaught ReferenceError: exports is not defined and require
问题描述
我使用angularjs和typescript来创建一些应用程序,我遇到这个错误的麻烦,我无法解决
I'm using angularjs and typescript to create some app, I'm having a trouble with this error that I can't solve
这是我的*。 ts code
Here is my *.ts code
export var NgApp = new application.Startup();
///<reference path="../../../../../typings/tsd.d.ts"/>
import {NgApp} from "../../bootstrap";
module views.components.home {
export class HomeComponent {
public constructor() {
}
public static factory():Function[] {
return [
() => new HomeComponent()
]
}
}
}
NgApp.registerComponents(views.components.home,() => this.app.controller);
这是我的GULP任务
let tsResult = gulp.src('src/**/*.ts').pipe(ts({
module: 'commonjs',
sourceMap: true
}));
let taskTs = tsResult.js.pipe(gulp.dest('built/'));
这是我的错误:
未捕获ReferenceError:导出未定义
This is my error: Uncaught ReferenceError: exports is not defined
问题是:如何在打字机中使用像es6这样的导入?我缺少什么?
The question is: How can I use import like es6 in typescript? What I am missing?
推荐答案
我使用角度1.6和webpack,
它工作在我身边,当我改变模块到umd
I use angular 1.6 and webpack, it works on my side when i changed the module to "umd"
UMD:通用模块定义这带来了一个
通用模式支持两种风格(AMD和CommonJS)
UMD: Universal Module Definition This has brought about the push for a "universal" pattern that supports both styles (AMD and CommonJS)
参考: http://davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/
粘贴在这里是我的tsconfig.json之后我改变了,我运行$ tsc
pasted here is my tsconfig.json after I changed it, I run $ tsc
{
"compilerOptions": {
"target": "es5",
"module": "umd",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"allowUnreachableCode": true
},
"exclude": [
"node_modules"
]
}
然后我的导出未定义错误消失。
这篇关于未捕获ReferenceError:导出未定义并且需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!