개요
Node.js 프로젝트 세팅을 하고 index.js에서
Common JS 방식이 아니라 ES 방식으로 import 해줬는데
SyntaxError: Cannot use import statement outside a module 가 떴다.
/* const express = require("express"); */ //common JS 방식
import express from "express"; //ES6
해결법
package.json에서 아래 코드를 추가해줘야 한다.
"type": "module"
"type"을 따로 설정해주지 않았거나 "commonjs"로 설정되어 있으면 기본적으로 commonjs 방식으로 설정되기 때문에 type 필드 값을 module로 설정해줘야 es6 방식으로 처리된다.
728x90
'study > Server' 카테고리의 다른 글
[Database] 데이터베이스 Master-Slave 구조란? (0) | 2024.11.04 |
---|---|
[Gradle] 스프링부트 빌드 시 plain.jar vs .jar 차이점 (0) | 2024.09.24 |
Caddy로 도메인 없이 https 설정하기 (1) | 2024.09.07 |
HTTP 응답 헤더, Content-Disposition (0) | 2024.08.01 |