简体   繁体   English

捆绑后,Javascript无法识别打字稿要求

[英]Javascript doesn't recognize typescript require after bundling

Here is my angular module written typescript. 这是我的角度模块书面打字稿。

  /// <reference path="../../../../thirdparty/angular/angular.d.ts"/>

 /// <reference path="./sharedData.ts"/>
 import factory = require('./sharedData');

 var  sharedData: ng.IModule = angular.module('comp.modules.common.sharedData', []);
sharedData.factory('sharedData', function () {
    return new factory.sharedData_factories.SharedData();
});
export {sharedData};

It works fine in local. 它在本地工作正常。 After bundling it gets compiled into the following js code where the js cannot find the keyword "require". 捆绑后,它将被编译成以下js代码,其中js无法找到关键字“ require”。 Also, we are using traceur to convert some of our ES6 modules to ES5. 另外,我们正在使用traceur将某些ES6模块转换为ES5。 Here is the compiled and bundled js module. 这是编译和捆绑的js模块。

     System.register("modules/common/sharedData/sharedData.module", [],   function($__export) {
   "use strict";
    var __moduleName = "modules/common/sharedData/sharedData.module";
  var factory,
  sharedData;
  return {
 setters: [],
 execute: function() {
  factory = require('./sharedData');
  sharedData = angular.module('comp.modules.common.sharedData', []);
  exports.sharedData = sharedData;
  sharedData.factory('sharedData', function() {
    return new factory.sharedData_factories.SharedData();
  });
       }
     };
 });

Also here is the tsconfig.Json 这也是tsconfig.Json

  {
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"sourceMap": true
  }
 }

into the following js code where the js cannot find the keyword "require" 进入以下js代码,其中js找不到关键字“ require”

The js you shared does not contain require . 您共享的js不包含require

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM