【问题标题】:RxJS root directory Not Found by SystemJSSystemJS 未找到 RxJS 根目录
【发布时间】:2016-03-12 11:42:01
【问题描述】:

SystemJS 似乎可以毫无问题地加载 rxjs 模块,但会在 rxjs 目录本身上抛出 404 Not Found。所有模块都是最新版本,这似乎只是 Windows 上的问题,它适用于 osx。

GET http://localhost:8080/node_modules/rxjs/ 404(未找到)

错误:错误:XHR 错误(404 未找到) XHR 完成加载:GET " localhost:8080/node_modules/rxjs/Subject.js"。

XHR 完成加载:GET "localhost:8080/node_modules/rxjs/operator/toPromise.js"。

Module loads & Error

<script>
    System.config({
        packages: {
            app: {
                format: 'register',
                defaultExtension: 'js',

            },
            'components':{ format: 'register' },
            'rxjs': {defaultExtension: 'js'}
        },
        map: {'app': '/components',
            'rxjs': '../node_modules/rxjs',
            },


    });
    System.import('components/notes.js')
            .then(null, console.error.bind(console));
</script>
+-- angular2@2.0.0-beta.9
+-- bootstrap@3.3.6
+-- es6-promise@3.0.2
+-- es6-shim@0.33.3
+-- jquery@2.2.1
+-- reflect-metadata@0.1.2
+-- rxjs@5.0.0-beta.2
+-- systemjs@0.19.24
| +-- es6-module-loader@0.17.11
| `-- when@3.7.7
+-- typescript@1.8.7
`-- zone.js@0.5.15
  `-- es6-promise@3.1.2

我解决了这个问题,看来我在 .ts 中导入 rxjs 的方式已被弃用:

改成

import {Subject, Observable} from 'rxjs';

到:

import { Observable } from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject'; import { map } from 'rxjs/operator/map';

【问题讨论】:

  • 奇怪的事情,但是有很多关于如何使用 rxjs 库的建议,但这是唯一有效的!你真的应该使用from 'rxjs/Observable' 而不是from 'rxjs'
  • 只是......哇...... JS应该被法律禁止!

标签: javascript typescript npm rxjs systemjs


【解决方案1】:

您不应在系统配置中添加 rxjs 特殊内容。 SystemJs 默认支持node_modules 模块查找。

【讨论】:

【解决方案2】:

我也认为您不需要在 System.config 中添加 rxjs。它会自动处理它。就像在A2 5min Quick Start 中提到的那样,您只需将&lt;script src="node_modules/rxjs/bundles/Rx.js"&gt;&lt;/script&gt; 添加到您的 index.html 并将您的 SystemJS 指向您的主要组件,剩下的就交给它了。

【讨论】:

  • 为解决问题的 rxjs 添加了修正的导入语句。
猜你喜欢
  • 1970-01-01
  • 2013-07-02
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 2017-06-05
  • 1970-01-01
  • 2017-08-16
  • 2016-02-12
相关资源
最近更新 更多