storycraft / node-kakao

Loco protocol compatible library
MIT License
409 stars 115 forks source link

node-fetch 에러 #48

Closed raravel closed 4 years ago

raravel commented 4 years ago

dev 브렌치 최신 소스를 받고, build 를 하면 다음과 같은 오류가 뜹니다.

yarn build
yarn run v1.22.4
$ ./node_modules/.bin/tsc
node_modules/node-fetch/@types/index.d.ts:6:27 - error TS2307: Cannot find module 'abort-controller' or its corresponding type declarations.

6 import {AbortSignal} from 'abort-controller';
                            ~~~~~~~~~~~~~~~~~~

node_modules/node-fetch/@types/index.d.ts:7:8 - error TS1259: Module '"/home/youn/proj/node/node-kakao/node_modules/fetch-blob/index"' can only be default-imported using the 'esModuleInterop' flag

7 import Blob from 'fetch-blob';
         ~~~~

  node_modules/fetch-blob/index.d.ts:2:1
    2 export = Blob;
      ~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

node_modules/node-fetch/@types/index.d.ts:74:31 - error TS2304: Cannot find name 'URL'.

74  agent?: Agent | ((parsedUrl: URL) => Agent);
                                 ~~~

node_modules/node-fetch/@types/index.d.ts:94:4 - error TS2304: Cannot find name 'URLSearchParams'.

94  | URLSearchParams
      ~~~~~~~~~~~~~~~

src/api/web-api-client.ts:8:17 - error TS2614: Module '"../../node_modules/node-fetch/@types"' has no exported member 'RequestInit'. Did you mean to use 'import RequestInit from "../../node_modules/node-fetch/@types"' instead?

8 import fetch, { RequestInit } from "node-fetch";
                  ~~~~~~~~~~~

Found 5 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

abort-controller 모듈 추가 및 tsconfig.json 에다 esModuleInterop: true 를 추가하면 다음과 같은 오류가 뜹니다.

yarn build
yarn run v1.22.4
$ ./node_modules/.bin/tsc
node_modules/node-fetch/@types/index.d.ts:74:31 - error TS2304: Cannot find name 'URL'.

74  agent?: Agent | ((parsedUrl: URL) => Agent);
                                 ~~~

node_modules/node-fetch/@types/index.d.ts:94:4 - error TS2304: Cannot find name 'URLSearchParams'.

94  | URLSearchParams
      ~~~~~~~~~~~~~~~

src/api/web-api-client.ts:8:17 - error TS2614: Module '"../../node_modules/node-fetch/@types"' has no exported member 'RequestInit'. Did you mean to use 'import RequestInit from "../../node_modules/node-fetch/@types"' instead?

8 import fetch, { RequestInit } from "node-fetch";
                  ~~~~~~~~~~~

src/api/web-api-client.ts:92:28 - error TS2351: This expression is not constructable.
  Type 'typeof FormData' has no construct signatures.

92         let formData = new FormData();
                              ~~~~~~~~

  src/api/web-api-client.ts:9:1
    9 import * as FormData from "form-data";
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

src/kakao-api.ts:161:28 - error TS2351: This expression is not constructable.
  Type 'typeof FormData' has no construct signatures.

161         let formData = new FormData();
                               ~~~~~~~~

  src/kakao-api.ts:2:1
    2 import * as FormData from "form-data";
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

src/kakao-api.ts:212:28 - error TS2351: This expression is not constructable.
  Type 'typeof FormData' has no construct signatures.

212         let formData = new FormData();
                               ~~~~~~~~

  src/kakao-api.ts:2:1
    2 import * as FormData from "form-data";
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

Found 6 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

개발 환경은 다음과 같습니다.

DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=18.3
DISTRIB_CODENAME=sylvia
DISTRIB_DESCRIPTION="Linux Mint 18.3 Sylvia"
NAME="Linux Mint"
VERSION="18.3 (Sylvia)"
ID=linuxmint
ID_LIKE=ubuntu
PRETTY_NAME="Linux Mint 18.3"
VERSION_ID="18.3"
HOME_URL="http://www.linuxmint.com/"
SUPPORT_URL="http://forums.linuxmint.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/linuxmint/"
VERSION_CODENAME=sylvia
UBUNTU_CODENAME=xenial

노드 버전은 다음과 같습니다.

node: v14.4.0
yarn: 1.22.4
storycraft commented 4 years ago

에러 없이 잘 작동합니다.

테스트 커맨드 npm install && npm run build

테스트 환경 (dev 브랜치)

{
  '@storycraft/node-kakao': '3.0.3',
  npm: '6.14.5',
  ares: '1.16.0',
  brotli: '1.0.7',
  cldr: '37.0',
  icu: '67.1',
  llhttp: '2.0.4',
  modules: '83',
  napi: '6',
  nghttp2: '1.41.0',
  node: '14.5.0',
  openssl: '1.1.1g',
  tz: '2020a',
  unicode: '13.0',
  uv: '1.38.0',
  v8: '8.3.110.9-node.23',
  zlib: '1.2.11'
}
raravel commented 4 years ago

CentOS 6.4 node 10.19.0 npm 6.13.4 에서 빌드해본 결과, 정상 빌드되는 것을 확인했습니다.

node-fetch 로 인하여 노드 버전 호환성에 대해 문제가 생긴 것 같습니다. 버전을 3.0.0-beta.7 이 아니라 2.6.0 으로 진행할 수는 없나요?

raravel commented 4 years ago

이유도 모르는 상태로 잘 돼서 해결