티스토리 뷰
fetch
fetch()는 자바스크립트에서 지원하는 URL을 호출하여 불러오는 내장 라이브러리 함수 입니다.
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
Using the Fetch API - Web APIs | MDN
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the net
developer.mozilla.org
node-fetch
https://www.npmjs.com/package/node-fetch
node-fetch
A light-weight module that brings Fetch API to node.js. Latest version: 3.2.10, last published: 2 months ago. Start using node-fetch in your project by running `npm i node-fetch`. There are 27690 other projects in the npm registry using node-fetch.
www.npmjs.com
node.js 환경에서도 fetch(URL) 함수를 불러서 웹페이지의 데이터를 로드할 수 있습니다.
ERR_REQUIRE_ESM 에러
작업래포/node_modules/node-fetch/src/index.js require() of ES modules is not supported.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
위와 같은 에러는 node-fetch의 fetch 함수를 이용하려면 es module을 써야합니다.
즉, import fetch from 'node-fetch' 형태로 fetch 함수를 불러올 수 없음을 의미합니다.
에러해결과정
1. node-fetch 삭제하고 v2로 다운그레이드
( @types/node-fetch 추가 설치는 typescript 언어로 작업하는 경우에만 해당합니다.)
$ npm uninstall node-fetch
$ npm install node-fetch@v2
$ npm i @types/node-fetch
2. package.json 타입변경
{
...
"type": "module",
...
}
[참고자료]
require('node-fetch') gives ERR_REQUIRE_ESM
I just use const fetch = require('node-fetch') And I get Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js from C:\Users\Alex\Desktop\
stackoverflow.com
[NodeJS] node-fetch 에러 해결 - Error [ERR_REQUIRE_ESM]: require() of ES Module ~ from ~ not supported.
fetch를 추가하자 아래와 같은 에러가 발생했다.검색을 해보니 방법이 두가지 있는 것 같았다.1\. node-fetch 삭제 후 v2로 재다운로드2\. package.json의 타입 변경npm uninstall node-fetchnpm install node-fetc
velog.io
[자바스크립트] fetch() 함수로 원격 API 호출하기
Engineering Blog by Dale Seo
www.daleseo.com
'Backend > 꾸준히 TIL' 카테고리의 다른 글
[mysql] CLI 명령어로 mysql connection 부르기 (0) | 2022.10.15 |
---|---|
SSL (0) | 2022.10.15 |
[Node.js/HTTP 통신 테스트] query와 params의 차이 (0) | 2022.10.07 |
[Node.js / Express.js / MongoDB / Mongoose] 문제 풀이 설명 (1) | 2022.10.06 |
[Node.js/Javascript] commonJS 문법과 ES6 - require() 와 import 비교 (2) | 2022.10.05 |
- Total
- Today
- Yesterday
- 개발용어
- 바이트디그리
- Nest.js
- node.js
- Jekyll
- IT용어
- TDD
- gem
- 갓생살자
- jest
- typeORM
- MongoDB
- 미완
- nestjs
- OS
- nestjs jest
- git
- 한달독서
- Mongoose
- RDBMS
- 습관개선
- 스마트폰중독
- 클린아키텍쳐
- 한달어스
- vscode
- 디지털디톡스
- 나도 할 수 있다
- 참고
- TypeScript
- MySQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |