Verständnis von esModuleInterop in tsconfig.json: Wie man CommonJS-Module in TypeScript importiert
Hallo zusammen! Ich bin neu in TypeScript und bin beim Einrichten meines Projekts auf ein Problem gestoßen, das ich nicht verstehe. Ich habe ein Node.js-Projekt und verwende die beliebte Bibliothek `express`. Ich habe sie über npm installiert und auch die Typen (`@types/express`) installiert. Meine `tsconfig.json`-Datei sieht so aus:
```json
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true
}
}
```
Wenn ich versuche, express so zu importieren:
```typescript
import express from 'express';
```
gibt TypeScript einen Fehler aus: `Module '...' has no default export.` oder so etwas wie `This module is declared with 'export =' and can only be used with a default import when using the 'esModuleInterop' flag.`
Ich habe über das Flag `esModuleInterop` gelesen, verstehe aber nicht ganz, was es tut und warum das überhaupt ein Problem ist. Warum kann ich express nicht einfach so importieren, wie ich es in JavaScript gewohnt bin? Was ist der Unterschied zwischen `import