파일 수정기

bacccine·2022년 3월 15일
0

Hot Potato NyamyList

목록 보기
14/17

package.json에 "type":"module"을 추가한 이후 발생한 에러

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/ubuntu/Hot-Potato-Nyamy-List/fire_potato-be/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

require는 NodeJS에서 사용되고 있는 CommonJS 키워드이고, import는 ES2015에서 새롭게 도입된 키워드입니다. 둘다 다른 파일의 코드를 불러온다는 같은 목적을 가지고 있지만, 다른 문법 구조 지니고 있습니다.

const library = require("library")
import library from "library"

https://hsp0418.tistory.com/147

const getAllFood = async () => {
    const res = await fetch('http://185.162.75.92:3000/baccine', {
        method: 'GET',              // *GET, POST, PUT, DELETE, etc.
        mode: 'cors',               // no-cors, cors, *same-origin
        cache: 'no-cache',          // *default, no-cache, reload, force-cache, only-if-cached
        credentials: 'same-origin', // include, *same-origin, omit
        headers: {
            'Content-Type': 'application/json',
            // 'Content-Type': 'application/x-www-form-urlencoded',
        },
        redirect: 'follow',         // manual, *follow, error
        referrer: 'no-referrer',    // no-referrer, *client
        // body: JSON.stringify(data), // body data type must match "Content-Type" headerF);
    });

    if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
    else return res
};

0개의 댓글