1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

`pnpm dlx tsc`は使うべからず

Posted at

npx tsc の代替として pnpm dlx tsc を呼び出すと意味不明なエラーが返ってきます:

$ pnpm dlx tsc

                                                                               
                This is not the tsc command you are looking for                
                                                                               

To get access to the TypeScript compiler, tsc, from the command line either:

- Use npm install typescript to first add TypeScript to your project before using npx
- Use yarn to avoid accidentally running code from un-installed packages

これはnpxがローカルを探索した後に必要であればレジストリからダウンロードしてくるのに対し、pnpm dlxローカルを探索せずにレジストリから同名のパッケージをロードして実行するからです。
では、pnpm dlx typescript はどうでしょうか。実はこれも失敗します。

$ pnpm dlx typescript
Packages: +1
+
Progress: resolved 1, reused 1, downloaded 0, added 1, done
 ERR_PNPM_DLX_MULTIPLE_BINS  Could not determine executable to run. typescript has multiple binaries: tsc, tsserver

Try one of the following:
pnpm --package=typescript dlx tsc
pnpm --package=typescript dlx tsserver

というわけで、$ pnpm --package=typescript dlx tscを使うのは一つの正解です。

あるいは、すでにdevDependenciesに加えている場合はpnpm exec tscでも良いです。
ただし、pnpm execは先にpnpm installを走らせていないと失敗します。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?