从 rxjs 导入时出现意外令牌

问题描述 投票:0回答:1

我在 main.ts 的打字稿中有以下代码:

import { of } from "rxjs";
import { map } from 'rxjs/operators';

class Main {
  public process() {
    console.log("Hello world!!!");
    of(1, 2, 3).pipe(map(x => x * 2));
  }
}

let main: Main = new Main(); main.process();

当我跑步时

node main.ts
我收到:

main.ts:1
import { of } from "rxjs";
       ^

SyntaxError: Unexpected token {
←[90m    at Module._compile (internal/modules/cjs/loader.js:718:23)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:641:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:556:12)←[39m
←[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)←[39m
←[90m    at internal/main/run_main_module.js:17:11←[39m
node.js typescript rxjs
1个回答
0
投票

如果你想运行 rxjs,你需要在 package.json 中输入 type="module"

© www.soinside.com 2019 - 2024. All rights reserved.