inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

차세대 Node.js 백엔드 서버 개발(Fastify & Prisma & Typescript와 함께하는)

Fastify 기본 설정

똑같이 따라하고 오류나서 다시해보고 다시해보고 올려주신 코드 확인해봐도 계속 에러가 뜨는대요 ㅠ.ㅠ

해결된 질문

816

반짝반짝한 갈매기

작성한 질문수 1

0

PS C:\Users\ohdaesung\Desktop\study\fastify> npm start

> sample@1.0.0 start

> npm run build:live

> sample@1.0.0 build:live

> nodemon --watch 'src/**/*' --exec ts-node --esm src/main.ts --verbose

[nodemon] 3.0.3

[nodemon] to restart at any time, enter rs

[nodemon] or send SIGHUP to 12892 to restart

[nodemon] watching path(s): 'src\**\*'

[nodemon] watching extensions: ts,json

[nodemon] starting ts-node --esm src/main.ts

[nodemon] spawning

[nodemon] child pid: 17216

[nodemon] watching 4 files

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\ohdaesung\Desktop\study\fastify\src\main.ts

at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)

at defaultGetFormat (node:internal/modules/esm/get_format:203:36)

at defaultLoad (node:internal/modules/esm/load:143:22)

at async nextLoad (node:internal/modules/esm/hooks:750:22)

at async nextLoad (node:internal/modules/esm/hooks:750:22)

at async Hooks.load (node:internal/modules/esm/hooks:383:20)

at async handleMessage (node:internal/modules/esm/worker:199:18) {

code: 'ERR_UNKNOWN_FILE_EXTENSION'

}

[nodemon] app crashed - waiting for file changes before starting... ㅠ.ㅠ

node.js typescript rest-api prisma fastify

답변 1

0

Indie Coder

일단 해당 내용은 ts파일 즉 typescript 파일이 정상적으로 인식되지 않아서 나는 오류 같습니다.

일단 몇가지 확인을 좀 부탁드리겠습니다.

 

  1. 우선 첫번째로 다음과 같이 typescript가 gloabal 옵션으로 typescript를 설치했는지 확인 부탁드립니다.

npm i typescript -g

  1. 그리고 지금 세팅한 package.json과 tsconfig.json을 첨부 부탁드리겠습니다.

  2. 또 어떤 챕터까지 완료 후에 이런 오류가 나는지도 확인 부탁드리겠습니다.

해당사항들을 확인부탁드리겠습니다.

 

 

0

반짝반짝한 갈매기

타입스크립트 설치했습니다 ㅠ.ㅠ

다 작성후에 npm start 작동하면 오류가 납니다.

 

{
  "name": "sample",
  "version": "1.0.0",
  "description": "",
  "main": "main.ts",
  "type":"module",
  "scripts": {
    "start:build":"tsc -w --project tsconfig.json && npx -p tsconfig.json",
    "build:live":"nodemon --watch 'src/**/*' --exec ts-node --esm src/main.ts --verbose",
    "start":"npm run build:live" 
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "fastify": "^4.26.0"
  },
  "devDependencies": {
    "@types/node": "^20.11.16",
    "nodemon": "^3.0.3",
    "ts-node": "^10.9.2",
    "typescript": "^5.3.3"
  }
}

 

 

{
  "compilerOptions": {
    "module": "ES2022",                                /* Specify what module code is generated. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    "target": "ES2022",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "moduleResolution": "Node",                     /* Specify how TypeScript looks up a file from a given module specifier. */
    "outDir": "./dist",                                   /* Specify an output folder for all emitted files. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    "noFallthroughCasesInSwitch": true,               /* Enable error reporting for fallthrough cases in switch statements. */
    "isolatedModules": true,                          /* Ensure that each file can be safely transpiled without relying on other imports. */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "noImplicitAny": true,                            /* Enable error reporting for expressions and declarations with an implied 'any' type. */
    "useUnknownInCatchVariables": true,               /* Default catch clause variables as 'unknown' instead of 'any'. */
    "inlineSourceMap": true                          /* Include sourcemap files inside the emitted JavaScript. */
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "document",
    "backup"
  ],
  "ts-node":{
    "esm":true,
    "experimentalSpecifierResolution":"node"
  }
}

0

Indie Coder

터미널에서 node -v으로 현재 사용하고 있는 nodejs 버전도 확인 부탁드립니다.

강의에 말한 것 처럼 현재는 18버전의 node를 사용하고 있습니다.

그리고 추가로 현재 학습하고 있는 설치한 프로젝트 폴더를 복사해서 보내주시면 제가 한번 살펴보도록 하겠습니다.

git에 올리셔도 되고 구글클라우드에 올리고 링크를 알려주셔도 되니

해당 파일들을 보내주시기 바랍니다

1

Indie Coder

확인해 본 결과 윈도우 화경에서 nodemon하고 ts-node로 실행시키는데 문제가 있는 것 같습니다

그래서 윈도우의 경우

다음과 같이 tsx 모듈을 설치하고

npm i -D tsx

 

package.json에서 build:live를 다음과 같이 수정하고 실행하시면 되겠습니다.

  "scripts": {
    "start:build": "tsc -w --project tsconfig.json && npx -p tsconfig.json",
    "build:live": "npx tsx src/main.ts",
    "start": "npm run build:live"

 

하지만 이렇게 실행할 경우 nodemon의 도움을 받을 수 없어서 코드가 변경후에는

서버를 다시한번 실행해야만 합니다.

 

이후에 윈도우에서도 nodemon과 ts-node로 실행할 수 있다면 확인해서 다시 업데이트 하도록 하겠습니다.

이부분에 대해 혼란을 드려서 죄송합니다.

 

위사항을 참고하시고 혹시 계속해서 문제가 있다면 다시한번 문의 부탁드리겠습니다.

감사합니다.

 

0

반짝반짝한 갈매기

감사합니다. 해결되었습니다 ㅎㅎ

관리자 페이지 질문

0

7

1

19강 15_2) 템블릿에 List가 없는경우는 어떻게 해야되나요?

0

8

1

15강 12-3) 값 제출후 mysql 저장이 안됩니다.

0

11

2

존재하지 않는 일기 url입력 시 alert이 두 번 떠요

0

19

1

교재(3쇄)와 강의 내용 문의

0

30

2

코드 질문

0

25

1

call stack 표현이 잘못표현된것이 아닌가요?

0

66

2

전자책으로 구매인증 가능할까요?

0

72

1

이제 인프런에서 강의 더 안산다. 후져....

0

42

1

소스코드 어디서 다운받아요?

0

54

5

4주차 미션 게시판이 안보여요~

0

46

2

eas 빌드가 엄청 오래걸려서..

0

59

2

수강완료 후 문의 드립니다.

1

47

2

prisma migrate 오류

0

205

3

401 not expired token 에러 메세지는 언제 쓰이나요?

0

298

2

Swagger 문서 접근 권한

0

256

1

앱에 refreshToken을 전송할때 궁금한점이 있습니다.

0

352

2

배포-ubuntu에서 문제

0

254

1

openssl 설치후 적용 안되요

0

374

1

comment 기능

0

198

1

섹션 5 login 인증 기능

0

344

2

Prisma 환경 설정 질문있어요!

0

253

2

TypeError 관련하여 문의드립니다.

0

306

1

강좌의 샘플 프로젝트 파일을 올려주시면 좋을 것 같아요.

0

575

2