기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
TypeScriptAL2023에서 사용
참고
이 문서는 TypeScript 및 Node.js 기반 실행 환경에 대한 필수 정보를 제공합니다. 또한 일반적인 개발 워크플로를 다루고 TypeScript가 AL2023에 패키징되어 일관되고 재현 가능한 개발 환경을 제공하는 방법을 설명합니다.
TypeScriptnodejs20-typescript 또는 nodejs22-typescript 같이 Amazon Linux에서 사용할 수 있는 RPM 패키지가 시스템 수준에서 글로벌로 지원되는 각 Node.js 버전에 대해 별도로 TS 컴파일러를 설치하는 정확한 방법입니다.
tsc는 어떤 Node.js 버전에도 직접 종속되지 않습니다. 컴파일러는 target
Node.js 기반 런타임 설계에는 특정 약점이 있습니다. 즉, 호스트에서 하나의 런타임 버전만 지원하며 프로젝트 수준에서 모든 종속성의 재현성과 일관성이 필요합니다. 이로 인해 TypeScript를 사용하는 다음과 같은 일반적인 접근 방식이 생겼습니다. TS 컴파일러, 현재 Node.js 버전의 TS 기본 구성, 모든 소프트웨어 종속성이 프로젝트 내에 로컬로 설치됩니다. 글로벌로 설치된 노드 모듈은 npm 같은 CLI 도구일 것으로 예상되지만, CLI 도구이기도 한 tsc가 글로벌로 설치되는 경우는 거의 없습니다. 다행히 tsc의 글로벌(시스템 전체) 및 로컬(프로젝트 내) 설치는 문제 없이 공존할 수 있으며 독립적으로 사용되는 다른 버전일 수도 있습니다. 로컬로 설치된 tsc는 npm과 함께 설치되는 npx 도구를 사용하여 실행해야 합니다. 따라서 시스템 TS 컴파일러를 사용하더라도 사용자는 Node.js(대체를 통해 활성 버전을 전환), TS 컴파일러(로컬 또는 글로벌로 설치 후 대체를 통해 활성 버전 전환) 등 런타임 구성 요소의 버전하고 특정 요구 사항에 맞게 구성할 수 있습니다.
Amazon Linux는 npm 같이 글로벌로 설치된 다른 노드 모듈과 동일한 방식으로 Node.js 버전별로 TS 컴파일러를 패키징합니다. 패키지 및 바이너리는 네임스페이스가 지정되며 이름의 일부로 Node.js의 메이저 버전을 포함합니다. 컴파일러의 기본 실행 파일 이름인 tsc는 대체 도구에 의해 런타임 시 관리되며 설치되어 실행될 Node.js의 현재 활성 버전을 가리킵니다. 이 선택은 현재 Node.js 런타임 버전에 종속되지 않습니다. 노드 실행 파일이 Node.js 20을 가리키고 tsc가 Node.js 22로 해석되도록 구성할 수 있습니다. TS 컴파일러의 네임스페이스 이름(예: tsc-{MAJOR_VERSION})을 기본 tsc 이름 구성과 독립적으로 사용할 수도 있습니다.
TS 컴파일러의 활성 버전을 관리하는 데 유용한 몇 가지 명령
-
다음에 대해 구성된 대체 확인
alternatives --list -
tsc의 현재 구성 확인
alternatives --display tsc -
대화형으로 tsc 버전 변경
alternatives --config tsc -
수동 모드로 전환하고 특정 버전 선택
alternatives --set tsc /usr/bin/tsc-{MAJOR_VERSION} -
자동 버전 선택 모드로 다시 전환
alternatives --auto tsc
여러 버전의 노드와 TS 컴파일러를 동일한 시스템에 설치하고 사용하는 예제:
# Check the AL2023 release $ cat /etc/amazon-linux-release Amazon Linux release 2023.9.20250929 (Amazon Linux) # Install a TypeScript compiler for Node.js 20 and 22 # Node.js 20 and 22 will be installed automatically $ sudo dnf install -qy nodejs20-typescript nodejs22-typescript # Check what was installed $ rpm -q nodejs20 nodejs20-typescript nodejs22 nodejs22-typescript nodejs20-20.19.5-1.amzn2023.0.1.x86_64 nodejs20-typescript-5.9.2-1.amzn2023.0.1.noarch nodejs22-22.19.0-1.amzn2023.0.1.x86_64 nodejs22-typescript-5.9.2-1.amzn2023.0.1.noarch # Check the active version of Node.js - it is version 20 $ alternatives --display node node - status is auto. link currently points to /usr/bin/node-20 /usr/bin/node-20 - priority 100 slave npmrc: /usr/lib/nodejs20/lib/node_modules/npm/npmrc slave npm: /usr/bin/npm-20 slave npx: /usr/bin/npx-20 slave node_modules: /usr/lib/nodejs20/lib/node_modules /usr/bin/node-22 - priority 100 slave npmrc: /usr/lib/nodejs22/lib/node_modules/npm/npmrc slave npm: /usr/bin/npm-22 slave npx: /usr/bin/npx-22 slave node_modules: /usr/lib/nodejs22/lib/node_modules Current 'best' version is /usr/bin/node-20. # Check the active JS runtime version for TypeScript # Currently, the tsc compiler will be executed by Node.js 22 $ alternatives --display tsc tsc - status is auto. link currently points to /usr/bin/tsc-22 /usr/bin/tsc-22 - priority 100 slave tsserver: /usr/bin/tsserver-22 /usr/bin/tsc-20 - priority 100 slave tsserver: /usr/bin/tsserver-20 Current 'best' version is /usr/bin/tsc-22. # Check versions printed by executables $ node -v v20.19.5 $ tsc -v Version 5.9.2 # while the node is 20, tsc is executed by node 22 anyway $ head -1 /usr/bin/tsc #!/usr/bin/node-22 # However, instead of default executable names, e.g. node or tsc, # we can use namespaced names to target any installed version $ node-20 -v v20.19.5 $ node-22 -v v22.19.0 $ tsc-20 -v Version 5.9.2 $ tsc-22 -v Version 5.9.2 $ head -1 /usr/bin/tsc-20 #!/usr/bin/node-20 $ head -1 /usr/bin/tsc-22 #!/usr/bin/node-22