Skip to content

In NodeJS I get ReferenceError: XMLHttpRequest is not defined when using "rxjs/ajax" #7535

Closed as not planned
@kasir-barati

Description

@kasir-barati

Describe the bug

import { ajax } from 'rxjs/ajax';

const observable$ = ajax.get('https://reqres.in/api/users/2');

observable$.subscribe({
  next(data) {
    console.log(data);
  },
  complete() {
    console.info("And we're done, we've fetched all data we could!");
  },
  error(err) {
    console.error(err);
  },
});

A simple TS snippet with this tsconfig.json:

{
  "compilerOptions": {
    "module": "NodeNext",
    "declaration": true,
    "strict": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES2024",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "allowSyntheticDefaultImports": true,
    "incremental": false,
    "skipLibCheck": true
  },
  "exclude": ["node_modules", "dist"]
}

And this pacakge.json:

{
  "name": "rxjs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "ts-node"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "rxjs": "^7.8.1",
    "ts-node": "^10.9.2"
  }
}

Expected behavior

Just work

Reproduction code

N/A.

Reproduction URL

No response

Version

7.8.1

Environment

Linux, Ubuntu

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions