[error] Node.js Error <SyntaxError: Cannot use import statement outside a module>
·
study/Server
개요 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 방식으로 처리된다.
cowboysj
'type' 태그의 글 목록