웹사이트 검색

typescript - esModuleInterop: true임에도 불구하고 TSLint가 다음과 같은 오류를 내보냄: "esModuleInterop 플래그를 사용해야만 default-import가 가능함"


아래 두 개의 기본 가져오기에서 왜 제목 오류가 발생하는지 잘 모르겠습니다:

// ./src/classes/FirestoreConnection.ts

import admin, {firestore} from "firebase-admin";
import firebase from "firebase";

// TS1259: Module '"/home/owner/PhpstormProjects/shopify/project/node_modules/firebase/index"' can only be default-imported using the 'esModuleInterop' flag  index.d.ts(8790, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.


TS1259: Module '"/home/owner/PhpstormProjects/shopify/buyUsedCloudRun/node_modules/firebase/index"' can only be default-imported using the 'esModuleInterop' flag  index.d.ts(8790, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

플래그가 true로 설정된 것을 봤는데, 아래에 다른 설정과 충돌이 있나요?

./tsconfig.json
{
  "compilerOptions" : {
    "module" : "commonjs",
    "target" : "es5",
    "sourceMap" : true,
    "esModuleInterop" : true,
    "types" : ["jest", "node"],
    "outDir" : "build",
    "allowSyntheticDefaultImports" : true,
    "moduleResolution" : "Node"
  },
  "exclude" : [
    "node_modules"
    , ".idea"
    , "build"
    , "**/*.test.ts"
  ],
  "include" : ["src/*"],
  "lib" : ["dom", "es2015", "es2017"],
  "skipLibCheck": false,
  "strict": false,
  "noEmit": false,
  "resolveJsonModule": true,
  "isolatedModules": false
}

답변 #1

from을 = require 구문으로 대체하고, 명명된 내보내기를 새 줄로 이동하여 해결했습니다. https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require

import admin = require("firebase-admin");
import {firestore } from "firebase-admin";
import firebase = require("firebase");