How to correctly declare or require in reference to the rxjs library?










0














Using nodejs and typescript to review another answer to a different question, I get this exception:




TypeError: interval$.zip is not a function




My code (rxjs2.ts):




var Rx = require('rxjs');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1,2,3]);

const itemsOverTime$ = interval$.zip(items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);



Running this from VSCode console, like: node rxjs2.ts



My package-lock.json




"requires": true,
"lockfileVersion": 1,
"dependencies":
"@types/node":
"version": "10.12.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ=="
,
"rxjs":
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
"integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
"requires":
"tslib": "1.9.3"

,
"tslib":
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="












share|improve this question



















  • 1




    What version of rxjs is this?
    – Phix
    Nov 13 '18 at 3:05















0














Using nodejs and typescript to review another answer to a different question, I get this exception:




TypeError: interval$.zip is not a function




My code (rxjs2.ts):




var Rx = require('rxjs');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1,2,3]);

const itemsOverTime$ = interval$.zip(items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);



Running this from VSCode console, like: node rxjs2.ts



My package-lock.json




"requires": true,
"lockfileVersion": 1,
"dependencies":
"@types/node":
"version": "10.12.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ=="
,
"rxjs":
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
"integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
"requires":
"tslib": "1.9.3"

,
"tslib":
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="












share|improve this question



















  • 1




    What version of rxjs is this?
    – Phix
    Nov 13 '18 at 3:05













0












0








0







Using nodejs and typescript to review another answer to a different question, I get this exception:




TypeError: interval$.zip is not a function




My code (rxjs2.ts):




var Rx = require('rxjs');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1,2,3]);

const itemsOverTime$ = interval$.zip(items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);



Running this from VSCode console, like: node rxjs2.ts



My package-lock.json




"requires": true,
"lockfileVersion": 1,
"dependencies":
"@types/node":
"version": "10.12.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ=="
,
"rxjs":
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
"integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
"requires":
"tslib": "1.9.3"

,
"tslib":
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="












share|improve this question















Using nodejs and typescript to review another answer to a different question, I get this exception:




TypeError: interval$.zip is not a function




My code (rxjs2.ts):




var Rx = require('rxjs');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1,2,3]);

const itemsOverTime$ = interval$.zip(items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);



Running this from VSCode console, like: node rxjs2.ts



My package-lock.json




"requires": true,
"lockfileVersion": 1,
"dependencies":
"@types/node":
"version": "10.12.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ=="
,
"rxjs":
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
"integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
"requires":
"tslib": "1.9.3"

,
"tslib":
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="









node.js rxjs require






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 14:24







Adam Cox

















asked Nov 13 '18 at 2:12









Adam CoxAdam Cox

953918




953918







  • 1




    What version of rxjs is this?
    – Phix
    Nov 13 '18 at 3:05












  • 1




    What version of rxjs is this?
    – Phix
    Nov 13 '18 at 3:05







1




1




What version of rxjs is this?
– Phix
Nov 13 '18 at 3:05




What version of rxjs is this?
– Phix
Nov 13 '18 at 3:05












1 Answer
1






active

oldest

votes


















0














Your imports are wrong and also the way you access the imports.



This should work:



StackBlitz



import interval, from, zip from 'rxjs';
import repeat from 'rxjs/operators';

const interval$ = interval(1000);
const items$ = from([1, 2, 3]);

const itemsOverTime$ = zip(interval$, items$).pipe(repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE:
Here is a solution for CommonJS imports. You need to install rxjs-compat with npm, if you prefer to use the old syntax and imports. Look at this documentation Rxjs Doc.



Stackblitz



const Rx = require('rxjs/Rx');
const repeat = require('rxjs/operator/repeat');


const interval$ = Rx.Observable.interval(1000);
const items$ = Rx.Observable.from([1, 2, 3]);

const itemsOverTime$ = Rx.Observable.zip(interval$, items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE 2:



For CommonJS and the new version of RxJs you need to do it like this:



StackBlitz



const Rx = require('rxjs');
const RxOp = require('rxjs/operators');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1, 2, 3]);

const itemsOverTime$ = Rx.zip(interval$, items$).pipe(RxOp.repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);





share|improve this answer






















  • How should I set up my environment to support the import? I get SyntaxError: Unexpected token import because I am using nodejs, and there is no support for import. See answer here: stackoverflow.com/questions/39436322/…
    – Adam Cox
    Nov 13 '18 at 14:21











  • @AdamCox I edited my answer to add a solution with CommonJs.
    – ams
    Nov 13 '18 at 22:00










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272781%2fhow-to-correctly-declare-or-require-in-reference-to-the-rxjs-library%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Your imports are wrong and also the way you access the imports.



This should work:



StackBlitz



import interval, from, zip from 'rxjs';
import repeat from 'rxjs/operators';

const interval$ = interval(1000);
const items$ = from([1, 2, 3]);

const itemsOverTime$ = zip(interval$, items$).pipe(repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE:
Here is a solution for CommonJS imports. You need to install rxjs-compat with npm, if you prefer to use the old syntax and imports. Look at this documentation Rxjs Doc.



Stackblitz



const Rx = require('rxjs/Rx');
const repeat = require('rxjs/operator/repeat');


const interval$ = Rx.Observable.interval(1000);
const items$ = Rx.Observable.from([1, 2, 3]);

const itemsOverTime$ = Rx.Observable.zip(interval$, items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE 2:



For CommonJS and the new version of RxJs you need to do it like this:



StackBlitz



const Rx = require('rxjs');
const RxOp = require('rxjs/operators');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1, 2, 3]);

const itemsOverTime$ = Rx.zip(interval$, items$).pipe(RxOp.repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);





share|improve this answer






















  • How should I set up my environment to support the import? I get SyntaxError: Unexpected token import because I am using nodejs, and there is no support for import. See answer here: stackoverflow.com/questions/39436322/…
    – Adam Cox
    Nov 13 '18 at 14:21











  • @AdamCox I edited my answer to add a solution with CommonJs.
    – ams
    Nov 13 '18 at 22:00















0














Your imports are wrong and also the way you access the imports.



This should work:



StackBlitz



import interval, from, zip from 'rxjs';
import repeat from 'rxjs/operators';

const interval$ = interval(1000);
const items$ = from([1, 2, 3]);

const itemsOverTime$ = zip(interval$, items$).pipe(repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE:
Here is a solution for CommonJS imports. You need to install rxjs-compat with npm, if you prefer to use the old syntax and imports. Look at this documentation Rxjs Doc.



Stackblitz



const Rx = require('rxjs/Rx');
const repeat = require('rxjs/operator/repeat');


const interval$ = Rx.Observable.interval(1000);
const items$ = Rx.Observable.from([1, 2, 3]);

const itemsOverTime$ = Rx.Observable.zip(interval$, items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE 2:



For CommonJS and the new version of RxJs you need to do it like this:



StackBlitz



const Rx = require('rxjs');
const RxOp = require('rxjs/operators');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1, 2, 3]);

const itemsOverTime$ = Rx.zip(interval$, items$).pipe(RxOp.repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);





share|improve this answer






















  • How should I set up my environment to support the import? I get SyntaxError: Unexpected token import because I am using nodejs, and there is no support for import. See answer here: stackoverflow.com/questions/39436322/…
    – Adam Cox
    Nov 13 '18 at 14:21











  • @AdamCox I edited my answer to add a solution with CommonJs.
    – ams
    Nov 13 '18 at 22:00













0












0








0






Your imports are wrong and also the way you access the imports.



This should work:



StackBlitz



import interval, from, zip from 'rxjs';
import repeat from 'rxjs/operators';

const interval$ = interval(1000);
const items$ = from([1, 2, 3]);

const itemsOverTime$ = zip(interval$, items$).pipe(repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE:
Here is a solution for CommonJS imports. You need to install rxjs-compat with npm, if you prefer to use the old syntax and imports. Look at this documentation Rxjs Doc.



Stackblitz



const Rx = require('rxjs/Rx');
const repeat = require('rxjs/operator/repeat');


const interval$ = Rx.Observable.interval(1000);
const items$ = Rx.Observable.from([1, 2, 3]);

const itemsOverTime$ = Rx.Observable.zip(interval$, items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE 2:



For CommonJS and the new version of RxJs you need to do it like this:



StackBlitz



const Rx = require('rxjs');
const RxOp = require('rxjs/operators');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1, 2, 3]);

const itemsOverTime$ = Rx.zip(interval$, items$).pipe(RxOp.repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);





share|improve this answer














Your imports are wrong and also the way you access the imports.



This should work:



StackBlitz



import interval, from, zip from 'rxjs';
import repeat from 'rxjs/operators';

const interval$ = interval(1000);
const items$ = from([1, 2, 3]);

const itemsOverTime$ = zip(interval$, items$).pipe(repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE:
Here is a solution for CommonJS imports. You need to install rxjs-compat with npm, if you prefer to use the old syntax and imports. Look at this documentation Rxjs Doc.



Stackblitz



const Rx = require('rxjs/Rx');
const repeat = require('rxjs/operator/repeat');


const interval$ = Rx.Observable.interval(1000);
const items$ = Rx.Observable.from([1, 2, 3]);

const itemsOverTime$ = Rx.Observable.zip(interval$, items$).repeat();

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);


UPDATE 2:



For CommonJS and the new version of RxJs you need to do it like this:



StackBlitz



const Rx = require('rxjs');
const RxOp = require('rxjs/operators');

const interval$ = Rx.interval(1000);
const items$ = Rx.from([1, 2, 3]);

const itemsOverTime$ = Rx.zip(interval$, items$).pipe(RxOp.repeat());

itemsOverTime$.subscribe(([time, val]) =>
console.log(val);
// 1
// 2
// 3
// 1
// 2
// 3
);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 22:14

























answered Nov 13 '18 at 3:03









amsams

2187




2187











  • How should I set up my environment to support the import? I get SyntaxError: Unexpected token import because I am using nodejs, and there is no support for import. See answer here: stackoverflow.com/questions/39436322/…
    – Adam Cox
    Nov 13 '18 at 14:21











  • @AdamCox I edited my answer to add a solution with CommonJs.
    – ams
    Nov 13 '18 at 22:00
















  • How should I set up my environment to support the import? I get SyntaxError: Unexpected token import because I am using nodejs, and there is no support for import. See answer here: stackoverflow.com/questions/39436322/…
    – Adam Cox
    Nov 13 '18 at 14:21











  • @AdamCox I edited my answer to add a solution with CommonJs.
    – ams
    Nov 13 '18 at 22:00















How should I set up my environment to support the import? I get SyntaxError: Unexpected token import because I am using nodejs, and there is no support for import. See answer here: stackoverflow.com/questions/39436322/…
– Adam Cox
Nov 13 '18 at 14:21





How should I set up my environment to support the import? I get SyntaxError: Unexpected token import because I am using nodejs, and there is no support for import. See answer here: stackoverflow.com/questions/39436322/…
– Adam Cox
Nov 13 '18 at 14:21













@AdamCox I edited my answer to add a solution with CommonJs.
– ams
Nov 13 '18 at 22:00




@AdamCox I edited my answer to add a solution with CommonJs.
– ams
Nov 13 '18 at 22:00

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272781%2fhow-to-correctly-declare-or-require-in-reference-to-the-rxjs-library%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto