2

我再次遇到此错误,上次我已修复但不知道如何修复但再次发生。

我安装了 ngstorage 模块,并且 projecr 在开发时运行良好(gulp clean serve)但是当它进入生产时(gulp serve:dist),它执行良好但主页是空白的并且控制台中有错误

未捕获的错误:[$injector:modulerr] 无法实例化模块应用程序,原因是:错误:[$injector:modulerr] 无法实例化模块 ngStorage,原因是:错误:[$injector:nomod] 模块“ngStorage”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。 http://errors.angularjs.org/1.5.8/$injector/nomod?p0=ngStorage _

尽管我已经检查过它是否已安装,但有人可以提出问题所在以及如何解决这个问题吗?这是我的 bower.json

{
  "name": "project",
  "version": "0.1.1",
  "dependencies": {
    "angular-animate": "1.5.8",
    "angular-touch": "~1.5.0",
    "angular-sanitize": "~1.5.0",
    "angular-messages": "~1.5.0",
    "angular-aria": "~1.5.0",
    "jquery": "~2.1.4",
    "angular-resource": "~1.5.0",
    "angular-ui-router": "~0.2.15",
    "bootstrap": "~3.3.6",
    "angular-bootstrap": "~1.1.2",
    "angular-toastr": "~2.0.0",
    "moment": "~2.13.0",
    "animate.css": "~3.4.0",
    "angular": "~1.5.0",
    "ng-table": "^1.0.0",
    "pace": "~1.0.2",
    "metisMenu": "~2.0.2",
    "fontawesome": "~4.5.0",
    "roboto-fontface": "^0.7.0",
    "angular-ui-validate": "^1.2.2",
    "ng-stomp": "^0.2.0",
    "angular-scrollable-table": "^1.1.1",
    "aws-sdk": "aws-sdk-js#^2.7.7",
    "ng-file-upload": "^12.2.13",
    "angular-recaptcha": "^4.0.3",
    "ng-csv": "^0.3.6",
    "ngstorage": "^0.3.11",
    "intl-tel-input": "5.1.7",
    "international-phone-number": "^0.0.16",
    "angular-chart.js": "^1.1.1"
  },
  "devDependencies": {
    "angular-mocks": "1.5.8"
  },
  "overrides": {
    "bootstrap": {
      "main": [
        "less/bootstrap.less",
        "dist/fonts/glyphicons-halflings-regular.eot",
        "dist/fonts/glyphicons-halflings-regular.svg",
        "dist/fonts/glyphicons-halflings-regular.ttf",
        "dist/fonts/glyphicons-halflings-regular.woff",
        "dist/fonts/glyphicons-halflings-regular.woff2"
      ]
    },
    "fontawesome": {
      "main": [
        "less/font-awesome.less",
        "fonts/fontawesome-webfont.eot",
        "fonts/fontawesome-webfont.svg",
        "fonts/fontawesome-webfont.ttf",
        "fonts/fontawesome-webfont.woff",
        "fonts/fontawesome-webfont.woff2"
      ]
    },
    "roboto-fontface": {
      "main": [
        "css/roboto/less/roboto-fontface.less"
      ]
    },
    "chart.js": {
               "main": [
                   "dist/Chart.bundle.min.js"
               ]
           }
   },
  "resolutions": {
    "jquery": "~2.1.4",
    "angular": "1.5.8"
  },      
  "description": "Project Manager On-Premise",
  "main": "",
  "homepage": "index.html",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ]
}

我认为存在与 stmop 相关的问题,或者我正在使用 broswer-sync ,这可能是原因但不能确定。

控制台图像

4

1 回答 1

1

问题是由于库之一——包含在它的主 js 文件中缺少分号

原因:

我在我的项目中使用ng-stomp并安装了这个库bower install,当我运行gulp dist:serve它时,它缩小了主要bower.json文件中提到的所有文件,它读取了 bower_components/ng-stomp/package.json主文件位置是 "main": "src/ng-stomp.js"并且这个文件最后缺少分号,所以当下一个 js 库(ngStorage)被缩小时,它的解析器无法识别它并抛出错误。

解决方案:

通过在我的bower.json 覆盖块中编写以下代码来覆盖主文件(添加最后有分号的ng-stomp.min.js )

 "ng-stomp": {
            "main": [
                "dist/ng-stmop.min.js"
            ]
        }

希望它可以帮助某人

于 2017-07-04T04:20:02.393 回答