question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rxjs imports don't work correctly

See original GitHub issue

I’m migrating my app over from a JSPM setup and running into issues with Rxjs Imports. Created a new app with ng new test-app so no crazy settings or something.

It might be that it’s just a misunderstanding on my part on how importing 3rd-party-packages works in angular-cli vs. jspm (where i can just jspm install abc and then import 'abc')

Error Msg When bootstrapping the app, I get:

angular2.dev.js:23941 TypeError: rxjs_1.BehaviorSubject is not a constructor
    at new CategoryService (category.service.ts:12)
    at angular2.dev.js:1418
    at Injector._instantiate (angular2.dev.js:11770)
    at Injector._instantiateProvider (angular2.dev.js:11709)
    at Injector._new (angular2.dev.js:11699)
    at InjectorDynamicStrategy.getObjByKeyId (angular2.dev.js:11577)
    at Injector._getByKeyDefault (angular2.dev.js:11900)
    at Injector._getByKey (angular2.dev.js:11854)
    at Injector._getByDependency (angular2.dev.js:11842)
    at Injector._instantiate (angular2.dev.js:11738)

Repro steps In a service I do (shortened for clarity):

import { BehaviorSubject, Subject } from 'rxjs'
export class MyService {
    public categories$: Subject<Array<Category>>

    constructor( private http: Http ) {
        this.categories$ = new BehaviorSubject([])
    }
}

index.html

  <body>
    <app>Loading...</app>

    <script src="vendor/es6-shim/es6-shim.js"></script>
    <script src="vendor/systemjs/dist/system-polyfills.js"></script>
    <script src="vendor/angular2/bundles/angular2-polyfills.js"></script>
    <script src="vendor/systemjs/dist/system.src.js"></script>

    <script src="vendor/angular2/bundles/angular2.dev.js"></script>
    <script src="vendor/angular2/bundles/http.dev.js"></script>
    <script src="vendor/angular2/bundles/router.dev.js"></script>
    <script src="vendor/papaparse/papaparse.js"></script>
    <script src="vendor/fuzzy/lib/fuzzy.js"></script>
    <script src="vendor/dropzone/dist/dropzone.js"></script>

    <script>
        System.config({
          map: {
            '@ngrx/store': 'vendor/@ngrx/store',
            'rxjs': 'vendor/rxjs'
          },
          packages: {
            app: {
              format: 'register',
              defaultExtension: 'js'
            },
            '@ngrx/store': {
              main: './dist/index.js'
            },
            'rxjs': {
              main: './bundles/Rx.js',
              map: {
                './BehaviorSubject': './subject/BehaviorSubject.js'
              }
            }
          }
        });
        System.import('app.js').then(null, console.error.bind(console));
    </script>
  </body>
  • also tried explicitly including Rx.js in a <script>-tag like in the default project => same result
  • also tried without 'rxjs': { map: … } => same result

angular-cli-build.js

/* global require, module */

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

module.exports = function(defaults) {
  var app = new Angular2App(defaults, {
    vendorNpmFiles: [
      '@ngrx/store/dist/*.js',
      'rxjs/**/*.js',
      'papaparse/papaparse.js',
      'fuzzy/lib/fuzzy.js',
      'dropzone/dist/dropzone.js'
    ]
  });
  return app.toTree();
};

Versions OSX 10.11.4 angular-cli: 0.0.31 node: 5.10.1 os: darwin x64

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
filipesilvacommented, Apr 22, 2016

Quite likely, yes. We’re still working on the process so that might change though. Current plan is to use SystemJS builder for production builds, and I believe it uses rollup internally so you’d end up only with stuff you use.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 5, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto imports not working properly with RxJS 7 beta #43034
Yes, first you need to import something from rxjs/operators in another file of the same project. This usually hints that rxjs/operators also has...
Read more >
Angular won't import Rxjs showing error - Stack Overflow
In rxjs6+ you need use pipeable operators, you can import them from 'rxjs/operators', in your case you need only map and share operators...
Read more >
Angular & TypeScript: How to Import RxJS Correctly?
Angular is based on RxJS, a library which makes reactive programming easy to use. There are different ways to import RxJS operators.
Read more >
Fix your RxJS 6 Imports & Operators - What's New in RxJS 6?
RxJS 6 was released and unlike older RxJS versions, it requires you to adjust your code. The import paths changed due to internal...
Read more >
RxJS Operators
A Pipeable Operator is a function that takes an Observable as its input and returns another Observable. It is a pure operation: the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found