J'essaie d'utiliser l'Observable avec le Javascript normal. J'ai suivi les instructions d'ici : https://www.npmjs.com/package/rxjs
Voici la séquence - je ne sais pas quel est le problème :
npm install rxjs
npm WARN test@1.0.0 No description
npm WARN test@1.0.0 No repository field.
+ rxjs@6.4.0
removed 13 packages, updated 1 package and audited 2 packages in 3.163s
found 0 vulnerabilities
------------------------------------------------------------
» cat package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "counter.js",
"dependencies": {
"rxjs": "^6.4.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
------------------------------------------------------------
» cat obs.js
import { range } from 'rxjs';
import { map, filter } from 'rxjs/operators';
range(1, 200).pipe(
filter(x => x % 2 === 1),
map(x => x + x)
).subscribe(x => console.log(x));
------------------------------------------------------------
» node obs.js
obs.js:1
(function (exports, require, module, __filename, __dirname) { import { range } from 'rxjs';
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
enter code here at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
------------------------------------------------------------