【问题标题】:ngMaterial fails to load on heroku but works on local machinengMaterial 无法在 heroku 上加载,但可以在本地机器上运行
【发布时间】:2017-04-10 16:46:26
【问题描述】:

Heroku 成功构建和部署。但是,当我尝试使用提供的 url 打开应用程序时,它会在浏览器中显示此错误

错误:[$injector:modulerr] 无法实例化模块 myApp 由于:

" 模块 'ngMaterial' 不可用!

让我感到困惑的是,本地一切运行良好,没有任何错误。我确实使用 --save 加载了 Angular Material 模块,并在

中包含了必要的脚本

{
  "name": "MyApp",
  "version": "0.0.0",
  "dependencies": {
    "angular-animate": "~1.5.3",
    "angular-ui-router": "~0.2.15",
    "bootstrap-sass": "~3.3.5",
    "angular-bootstrap": "~1.3.3",
    "malarkey": "yuanqing/malarkey#~1.3.1",
    "angular-toastr": "~1.5.0",
    "moment": "~2.10.6",
    "animate.css": "~3.4.0",
    "angular": "~1.5.3",
    "angular-material": "^1.1.3",
    "angular-spinners": "^3.1.2",
    "ang-accordion": "*",
    "angular-material-data-table": "^0.10.10",
    "jquery": "^3.1.1",
    "angular-cookies": "v1.5.11",
    "angular-aria": "1.5.10",
    "angular-messages": "^1.6.3"
  },
  "devDependencies": {
    "angular-mocks": "~1.5.3"
  },
  "overrides": {
    "bootstrap-sass": {
      "main": [
        "assets/stylesheets/_bootstrap.scss",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.eot",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.svg",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.ttf",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.woff",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.woff2"
      ]
    }
  },
  "resolutions": {
    "angular": "~1.5.3"
  }
}

过去 2 天我一直在寻找解决方案,但似乎没有什么对我有用。我附上了我的bower.jsonmyApp 模块和index.html 的sn-p。

angular.module('MyApp', ['ngAnimate','ui.router', 'ui.bootstrap', 'toastr','ngMaterial','ngAria'])
  .constant('malarkey', malarkey)
  .constant('moment', moment)
  .config(config)
  .config(routerConfig);
<!doctype html>
<html ng-app="myApp" ng-strict-di>

<head>
  <meta charset="utf-8">
  <title>My</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
  <link rel="stylesheet" href="./bower_components/animate.css/animations.css" />
  <link rel="stylesheet" href="./bower_components/angular-material/angular-material.css" />
  

  <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

  <!-- build:css({.tmp/serve,src}) styles/vendor.css -->
  <!-- bower:css -->
  <!-- run `gulp inject` to automatically populate bower styles dependencies -->
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:css({.tmp/serve,src}) styles/app.css -->
  <!-- inject:css -->
  <!-- css files will be automatically insert here -->
  <!-- endinject -->
  <!-- endbuild -->

</head>

<body>
  <!--[if lt IE 10]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->

  <acme-navbar></acme-navbar>

  <div ui-view>
  </div>

  <!-- build:js(src) scripts/vendor.js -->
  <!-- bower:js -->
  <!-- run `gulp inject` to automatically populate bower script dependencies -->
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:js({.tmp/serve,.tmp/partials}) scripts/app.js -->
  <!-- inject:js -->
  <!-- js files will be automatically insert here -->
  <!-- endinject -->

  <!-- inject:partials -->
  <!-- angular templates will be automatically converted in js and inserted here -->
  <!-- endinject -->
  <!-- endbuild -->


</body>
<acme-footer></acme-footer>
<script type="text/javascript" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
<!-- Used for JavaScript animations (include this before angular.js) -->
<script src="./bower_components/jquery/dist/jquery.js"></script>
<!-- Adds animation support in AngularJS -->
<script src="./bower_components/angular-animate/angular-animate.js"></script>
<!-- AngularJS Material Javascript now available via Google CDN; version 1.0.7 used here -->


<script src="./bower_components/angular-material/angular-material.js"></script>
<script src="./bower_components/angular-cookies/angular-cookies.js"></script>
</html>

关于如何解决我的问题有什么建议吗?

【问题讨论】:

  • 我会复制您的项目并删除您的 node_modules 文件夹和“npm install”,看看您是否遇到任何错误。您是否必须“构建”materializeng?
  • @CodyG。感谢您的快速回复。我确实删除了我的 node_modules 和 bower_components 文件夹并运行了“npm install”,但似乎没有解决任何问题。

标签: javascript angularjs node.js heroku mean-stack


【解决方案1】:

经过长时间的故障后,我终于明白了问题所在。这是模块 ngMaterial 所依赖的不兼容版本的依赖项。在我降级 ngMassages 之后,一切正常。谢谢。

{
  "name": "MyApp",
  "version": "0.0.0",
  "dependencies": {
    "angular-animate": "~1.5.3",
    "angular-ui-router": "~0.2.15",
    "bootstrap-sass": "~3.3.5",
    "angular-bootstrap": "~1.3.3",
    "malarkey": "yuanqing/malarkey#~1.3.1",
    "angular-toastr": "~1.5.0",
    "moment": "~2.10.6",
    "animate.css": "~3.4.0",
    "angular": "~1.5.3",
    "angular-material": "^1.1.3",
    "angular-spinners": "^3.1.2",
    "ang-accordion": "*",
    "angular-material-data-table": "^0.10.10",
    "jquery": "^3.1.1",
    "angular-cookies": "v1.5.11",
    "angular-aria": "1.5.10",
    "angular-messages": "^1.6.3"
  },
  "devDependencies": {
    "angular-mocks": "~1.5.3"
  },
  "overrides": {
    "bootstrap-sass": {
      "main": [
        "assets/stylesheets/_bootstrap.scss",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.eot",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.svg",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.ttf",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.woff",
        "assets/fonts/bootstrap/glyphicons-halflings-regular.woff2"
      ]
    }
  },
  "resolutions": {
    "angular": "~1.5.3"
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多