【发布时间】:2020-09-16 11:28:10
【问题描述】:
由于某种原因npx tsc --init 打印出以下错误:
$ npx tsc --init
npx: installed 1 in 1.467s
error TS5023: Unknown compiler option 'init'.
我已经用 Yarn 2 安装了typescript 包:
$ yarn add -D typescript
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 0.31s
➤ YN0000: ┌ Fetch step
➤ YN0013: │ typescript@npm:3.9.3 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ typescript@patch:typescript@npm%3A3.9.3#builtin<compat/typescript>::version=3.9.3&hash=8cac75 can't be found in the cache and will be fetched from the disk
➤ YN0000: └ Completed in 1.46s
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 1.95s
有人可以向我解释为什么tsc 无法识别--init 以及我做错了什么吗?
更新:
正如 Daniel 发现的那样,问题在于 npx 无法找到或识别使用 Yarn 2 安装的 typescript 软件包。解决方案是改用yarn:yarn tsc --init
【问题讨论】:
标签: node.js typescript yarnpkg tsc