问题描述
在学rxjs的时候想着写代码运行一下,
已经安装了 rxjs (npm install rxjs -g)
但是使用node test.js运行就报错,如下
import { Observable, of } from 'rxjs'
var source = of(1, 2, 3);
source.subscribe({
next(x) {
console.log(x);
}
})
报错:
解决方案:
网上一查原来node 环境并不支持es6 的import使用,所以这里就无法使用import导入了,可以将代码改为如下这样,使用require来导入
const rx = require("rxjs");
var source = rx.of(1, 2, 3);
source.subscribe({
next(x) {
console.log(x);
}
})