Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. 발생 시

 

node src/~.ts를 실행했을 때 아래와 같이 Warning과 함께 SyntaxError: Cannot use import statement outside a module과 같이 에러가 발생하였다.

 

package.json에 type이 "module"로 지정되어 있지 않아서 node로 src안의 ts 파일을 개별 실행시킬시 때 위와 같이 출력되었다.

 

위와 같이 package.json에 type: module을 추가하고 ts 파일을 실행 시 정상적으로 실행되었다.

 

'개발 > TypeScript' 카테고리의 다른 글

Date 타입을 유지하면서 전/후 Date 출력하기  (0) 2022.01.13