티스토리 뷰

OS | CS

[Mac M1] zsh: command not found: nest

김콩콩쥐 2024. 2. 6. 09:50

오류 발생

yarn 을 설치하고 yarn 을 통해 nestjs/cli 를 설치하려고 했는데 찾지 못하는 문제 발생

% yarn global add @nestjs/cli
yarn global v1.22.21
warning package.json: No license field
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Installed "@nestjs/cli@10.3.0" with binaries:
      - nest
✨  Done in 0.80s.
% nest new simple-board
zsh: command not found: nest

원인

yarn global 로 패키지를 설치하는 곳과 설치한 패키지를 호출했을 때 읽는 곳이 달라서 생긴 문제

해결방법

경로 재설정이 필요함

1. yarn 의 설치 경로 확인

% yarn global bin
warning package.json: No license field
/Users/[xxxx]/.yarn/bin

2. prefix 확인

% yarn config get prefix
warning package.json: No license field
undefined

내 경우엔 아무것도 설정되어있지 않음

3. prefix 설정

% yarn config set prefix ~/.yarn
yarn config v1.22.21
warning package.json: No license field
success Set "prefix" to "/Users/[xxx]/.yarn".
✨  Done in 0.01s.

4. path 값 변경

% vim ~/.zshrc

설정 파일 진입

export PATH="$PATH:`yarn global bin`"

위의 내용 하단에 저장

% source ~/.zshrc

위의 명령어로 설정 적용

5. 재설치

% yarn global add @nestjs/cli
yarn global v1.22.21
warning package.json: No license field
[1/4] 🔍  Resolving packages...
⠁ (node:49980) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Installed "@nestjs/cli@10.3.0" with binaries:
      - nest
✨  Done in 0.76s.

6. nestjs 프로젝트 생성

% nest new simple-board
⚡  We will scaffold your app in a few seconds..

? Which package manager would you ❤️  to use? yarn
CREATE simple-board/.eslintrc.js (663 bytes)
CREATE simple-board/.prettierrc (51 bytes)
CREATE simple-board/README.md (3347 bytes)
CREATE simple-board/nest-cli.json (171 bytes)
CREATE simple-board/package.json (1952 bytes)
CREATE simple-board/tsconfig.build.json (97 bytes)
CREATE simple-board/tsconfig.json (546 bytes)
CREATE simple-board/src/app.controller.ts (274 bytes)
CREATE simple-board/src/app.module.ts (249 bytes)
CREATE simple-board/src/app.service.ts (142 bytes)
CREATE simple-board/src/main.ts (208 bytes)
CREATE simple-board/src/app.controller.spec.ts (617 bytes)
CREATE simple-board/test/jest-e2e.json (183 bytes)
CREATE simple-board/test/app.e2e-spec.ts (630 bytes)

✔ Installation in progress... ☕

🚀  Successfully created project simple-board
👉  Get started with the following commands:

$ cd simple-board
$ yarn run start


                          Thanks for installing Nest 🙏
                 Please consider donating to our open collective
                        to help us maintain this package.


               🍷  Donate: https://opencollective.com/nest

성공 !


참고자료 - https://kyounghwan01.github.io/blog/etc/yarn-global/#해결방법