강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của s9gem8744120
s9gem8744120

câu hỏi đã được viết

Phát triển máy chủ phụ trợ Node.js thế hệ tiếp theo (với Fastify & Prisma & Typescript)

Cấu hình cơ bản Fastify

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

Đã giải quyết

Viết

·

549

0

따라 치면서 해보고 있는데, 오타 같은 부분으로 인해서 실제 실행하는데 있어 시간이 걸리는 부분이 있네요. ^^;

node.jstypescriptrest-apiprismafastify

Câu trả lời 2

0

hym님의 프로필 이미지
hym
Người đặt câu hỏi

강의 링크는 확인하였습니다. 감사합니다.

공유주신 내용으로 해도 안되네요;

> npm i typescript -g
> npm run start
...
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for
... 
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
[nodemon] app crashed - waiting for file changes before starting...

0

hym님의 프로필 이미지
hym
Người đặt câu hỏi

package.json

{
  "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"
  }
}

 

 

tsconfig.json

{
  "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"
  }
}

 

 

npm start


[nodemon] 3.0.3
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 45444 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: 39804
[nodemon] watching 5 files
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" 
..
hym님의 프로필 이미지
hym
Người đặt câu hỏi

위와 같이 ERR_UNKNOWN_FILE_EXTENSION 에러 발생

Indie Coder님의 프로필 이미지
Indie Coder
Người chia sẻ kiến thức

내용을 보니 'fastify 기본설정' 챕터를 진행중인걸로 예상되는데요

보내주신 설정파일 상으로는 아무 문제가 없는 것 같습니다.

그래서 몇가지 확인 부탁드리겠습니다.

  1. typescript를 -g 즉 전역으로 설정 하셨는지에 대해 확인 부탁드립니다.

npm i typescript -g

 

  1. 다음 링크는 fastify 기본 설정 까지 테스트한 내용입니다. 다음 파일을 압축 풀고 npm i를 이용해 패키지 설치 후 실행해 보시기 바랍니다. 만약 작동한다면 해당 링크의 코드와 작성하신 코드를 비교해 보시기 바랍니다.

     

     

    https://drive.google.com/file/d/1mrjpEHQhvXPxbgkEtHyV21txlpCFeOXJ/view?usp=drive_link

 

위의 사항을 확인 후에도 오류가 발생한다면 다시한번 문의 부탁드리겠습니다.

그리고 강좌의 샘플 코드의 경우 마지막 챕터에 링크가 있습니다. 이부분도 참고 하시기 바랍니다.

 

 

Hình ảnh hồ sơ của s9gem8744120
s9gem8744120

câu hỏi đã được viết

Đặt câu hỏi