未捕获的错误:无模块:MyApp的 [英] Uncaught Error: No module: MyApp

查看:143
本文介绍了未捕获的错误:无模块:MyApp的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在加载框架的NodeJS AngularJs和jQuery使用RequireJs。

I load AngularJs and jQuery using RequireJs in nodeJs framework.

这是main.js

    require.config({
    paths: {
        angular: 'vendor/angular.min',
        bootstrap: 'vendor/twitter/bootstrap',
        jquery: 'vendor/jquery-1.9.0.min',
        domReady: 'vendor/require/domReady',
        underscore: 'vendor/underscore.min'
    },
    shim: {
        angular: {
            deps: [ 'jquery' ],
            exports: 'angular'
        }
    }
});

require([
        'app',
        'angular-boot'
    ], function() {

});

在app.js

 define(['angular'], function (angular) {
    return angular.module('MyApp', []);
})

和在角boot.js

and in angular-boot.js

    define([ 'angular', 'domReady' ], function (angular, domReady) {
    domReady(function() {
        angular.bootstrap(document, ['MyApp']);
    });
});

在我的HTML文件,我只有这条线,以声明和使用requirejs。
不NG-AP或其他任何东西。

In my html file I have only this line, in order to declare and use requirejs. Not ng-ap or anything else.

<script data-main="js/main" src="js/require.js"></script>

的问题是,有时运行时,有时没有。
当它不运行误差

The problem is that sometimes runs, sometimes not. The error when it doesn't run is

未捕获的错误:没有模块:MyApp的

Uncaught Error: No module: MyApp

如果有任何关于它的想法,我就真的AP preciate它。
非常感谢你。

If there is any thought about it, I would really appreciate it. Thank you very much.

推荐答案

在您的垫片,你需要设置应用作为一个依赖于角启动。你的角启动文件依赖于应用(其中 MyApp的应用角启动负荷>并由此产生一个错误。

In your shim, you need to setup the app as a dependency to angular-boot. Your angular-boot file depends on app (where MyApp is defined), and because the load order for these two files is not specified, sometimes angular-boot loads before the app and thus produces that error.

要解决,只是更新您的垫片这样:

To remedy, just update your shim as such:

shim: {
  angular: {
    deps: [ 'jquery' ],
    exports: 'angular'
  },
  'angular-boot': {
    deps: ['app']
  }
}

和比,因为你并不需要包括应用程序明确你的要求调用可以简化为:

and than, since you don't need to include the 'app' explicitly your require call can be reduced to:

require(['angular-boot']);

这篇关于未捕获的错误:无模块:MyApp的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆