【问题标题】:JSPM Bundle with missing json files缺少 json 文件的 JSPM 捆绑包
【发布时间】:2017-06-09 08:55:33
【问题描述】:

我在执行命令时得到一个错误的捆绑文件:

jspm bundle src/main.js main-bundle.js

不包括 npm:@angular/animations@4.1.3.json 之类的文件,不包括 .json 文件,只包括 .js 文件,但是,如果我从 OSX 启动相同的命令,这些字段将包括在内

来自 OSX(有效的捆绑文件内容):

   npm:@angular/animations@4.1.3.json
   npm:@angular/animations@4.1.3/bundles/animations-browser.umd.min.js
   npm:@angular/animations@4.1.3/bundles/animations.umd.js
   npm:@angular/common@4.1.3.json
   npm:@angular/common@4.1.3/bundles/common.umd.js
   npm:@angular/compiler@4.1.3.json
   npm:@angular/compiler@4.1.3/bundles/compiler.umd.js
   npm:@angular/core@4.1.3.json
   npm:@angular/core@4.1.3/bundles/core.umd.js
   npm:@angular/forms@4.1.3.json
   npm:@angular/forms@4.1.3/bundles/forms.umd.js
   npm:@angular/http@4.1.3.json
   npm:@angular/http@4.1.3/bundles/http.umd.js
   npm:@angular/material@2.0.0-beta.6.json
   npm:@angular/material@2.0.0-beta.6/bundles/material.umd.js
   npm:@angular/platform-browser-dynamic@4.1.3.json
   npm:@angular/platform-browser-dynamic@4.1.3/bundles/platform-browser-dynamic.umd.js
   npm:@angular/platform-browser@4.1.3.json
   npm:@angular/platform-browser@4.1.3/bundles/platform-browser-animations.umd.min.js
   npm:@angular/platform-browser@4.1.3/bundles/platform-browser.umd.js
   npm:@angular/router@4.1.3.json
   npm:@angular/router@4.1.3/bundles/router.umd.js
   npm:core-js@2.4.1.json
   npm:core-js@2.4.1/client/shim.js
   npm:core-js@2.4.1/es6/reflect.js
   npm:core-js@2.4.1/es7/reflect.js

来自 Linux(错误的捆绑文件,缺少 json 包定义):

   npm:@angular/animations@4.1.3/bundles/animations-browser.umd.min.js
   npm:@angular/animations@4.1.3/bundles/animations.umd.js
   npm:@angular/common@4.1.3/bundles/common.umd.js
   npm:@angular/compiler@4.1.3/bundles/compiler.umd.js
   npm:@angular/core@4.1.3/bundles/core.umd.js
   npm:@angular/forms@4.1.3/bundles/forms.umd.js
   npm:@angular/http@4.1.3/bundles/http.umd.js
   npm:@angular/material@2.0.0-beta.6/bundles/material.umd.js
   npm:@angular/platform-browser-dynamic@4.1.3/bundles/platform-browser-dynamic.umd.js
   npm:@angular/platform-browser@4.1.3/bundles/platform-browser-animations.umd.min.js
   npm:@angular/platform-browser@4.1.3/bundles/platform-browser.umd.js
   npm:@angular/router@4.1.3/bundles/router.umd.js
   npm:core-js@2.4.1/client/shim.js
   npm:core-js@2.4.1/es6/reflect.js
   npm:core-js@2.4.1/es7/reflect.js
   npm:core-js@2.4.1/modules/_a-function.js

两者都使用相同版本的 jspm (0.17.0-beta.41)、systemjs (0.20.10) 和 systemjs-builder (0.16.4),我想这两种环境都有不同的影响,但我已经删除了 ~/.jspm 目录以获得具有相同结果的干净环境,但我不确定还有什么影响。

jspm.config.js 文件在两种情况下都是一样的:

SystemJS.config({
  nodeConfig: {
    "paths": {
      "github:": "jspm_packages/github/",
      "npm:": "jspm_packages/npm/"
    }
  },
  devConfig: {
    "map": {
      "plugin-typescript": "github:frankwallis/plugin-typescript@7.0.6",
      "typescript": "npm:typescript@2.3.4",
      "child_process": "npm:jspm-nodelibs-child_process@0.2.1",
      "module": "npm:jspm-nodelibs-module@0.2.1",
      "net": "npm:jspm-nodelibs-net@0.2.1"
    },
    "packages": {
      "npm:source-map-support@0.4.14": {
        "map": {
          "source-map": "npm:source-map@0.5.6"
        }
      },
      "npm:typescript@2.3.4": {
        "map": {
          "source-map-support": "npm:source-map-support@0.4.14"
        }
      }
    }
  },
  transpiler: false,
  packages: {
    "environments": {
      "defaultExtension": "js"
    },
    "src": {
      "defaultExtension": "js"
    }
  },
  map: {
    "@angular/animations/browser": "npm:@angular/animations@4.1.3/bundles/animations-browser.umd.min.js",
    "@angular/platform-browser/animations": "npm:@angular/platform-browser@4.1.3/bundles/platform-browser-animations.umd.min.js",
    "app": "src/app"
  }
});

SystemJS.config({
  packageConfigPaths: [
    "github:*/*.json",
    "npm:@angular/*.json",
    "npm:@covalent/*.json",
    "npm:*.json"
  ],
  map: {
    "@angular/animations": "npm:@angular/animations@4.1.3",
    "@angular/common": "npm:@angular/common@4.1.3",
    "@angular/compiler": "npm:@angular/compiler@4.1.3",
    "@angular/core": "npm:@angular/core@4.1.3",
    "@angular/forms": "npm:@angular/forms@4.1.3",
    "@angular/http": "npm:@angular/http@4.1.3",
    "@angular/material": "npm:@angular/material@2.0.0-beta.6",
    "@angular/platform-browser": "npm:@angular/platform-browser@4.1.3",
    "@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@4.1.3",
    "@angular/router": "npm:@angular/router@4.1.3",
    "@covalent/core": "npm:@covalent/core@1.0.0-beta.4",
    "@covalent/dynamic-forms": "npm:@covalent/dynamic-forms@1.0.0-beta.4",
    "@covalent/http": "npm:@covalent/http@1.0.0-beta.4",
    "angular-in-memory-web-api": "npm:angular-in-memory-web-api@0.3.1",
    "angular-safeguard": "npm:angular-safeguard@1.0.1",
    "assert": "npm:jspm-nodelibs-assert@0.2.1",
    "buffer": "npm:jspm-nodelibs-buffer@0.2.2",
    "constants": "npm:jspm-nodelibs-constants@0.2.1",
    "core-js": "npm:core-js@2.4.1",
    "crypto": "npm:jspm-nodelibs-crypto@0.2.1",
    "events": "npm:jspm-nodelibs-events@0.2.2",
    "file-saver": "npm:file-saver@1.3.3",
    "fs": "npm:jspm-nodelibs-fs@0.2.1",
    "hammerjs": "npm:hammerjs@2.0.8",
    "ng2-toastr": "npm:ng2-toastr@4.0.1",
    "os": "npm:jspm-nodelibs-os@0.2.1",
    "path": "npm:jspm-nodelibs-path@0.2.3",
    "process": "npm:jspm-nodelibs-process@0.2.1",
    "rxjs": "npm:rxjs@5.3.0",
    "stream": "npm:jspm-nodelibs-stream@0.2.1",
    "string_decoder": "npm:jspm-nodelibs-string_decoder@0.2.1",
    "timers": "npm:jspm-nodelibs-timers@0.2.1",
    "util": "npm:jspm-nodelibs-util@0.2.2",
    "vm": "npm:jspm-nodelibs-vm@0.2.1",
    "web-animations-js": "npm:web-animations-js@2.2.2",
    "zone.js": "npm:zone.js@0.8.5"
  },
  packages: {
      // SKIPPED //
  }
});

如果我理解正确,丢失的 json 文件被处理但不包括在内,文件“npm:@angular/http@4.1.3/bundles/http.umd.js”被包括在内,因为在“npm:@ angular/http@4.1.3.json”,但是,由于某种原因,包定义文件在包中被跳过了。

¿ 在这两个环境中我应该检查任何其他文件吗?欢迎任何想法。

更新:经过一些测试,我怀疑问题与systemjs-builder lib有关,而不是jspm

【问题讨论】:

  • 为什么要将这些文件包含在包中?他们只是告诉 jspm 在哪里寻找包含模块的实际 .js 文件。你需要什么?
  • 问题是如果没有这些文件,当我启动应用程序时,浏览器(systemjs)会尝试从服务器下载它们,因此返回 404。换句话说,将它们放在包中,这些库是在本地“注册”的,systemjs 知道该实现包含在包中。
  • 好的,让我们尝试从稍微不同的角度来解决这个问题 - 您是否尝试将应用程序作为单个文件分发?如果是,您应该使用jspm build
  • 我想要一个仅用于 js 文件的文件,“典型包”,无论如何,问题出在 SystemJS 构建器中,一个 env 中的 deps 解析包括 .json 文件,但不包括另一个。从调试中获得的示例,lib @angular/core@4.1.3/bundles/core.umd.js 应该包含 @angular/core@4.1.3.json 作为依赖项,但在其中一个 env 中不包含。

标签: javascript systemjs jspm building systemjs-builder


【解决方案1】:

最后,我发现了问题,如果带有 packageConfigPaths 的目录绝对路径包含“(”,则 lib systemjs-builder 中 utils.js 中的方法 getPackageConfigPath(...) 会失败(不返回任何内容)。

在 linux 中,jenkins 作业的名称类似于“MyProject (angular2)”,这导致构建过程找不到包中所有库的 packageConfigPath。

我在 github 项目上打开了一个 issue:https://github.com/systemjs/builder/issues/811

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-12
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    相关资源
    最近更新 更多