knip: Cannot find package 'typescript'

$ git clone https://github.com/taiga-family/taiga-ui.git
$ cd taiga-ui
$ npm ci 
$ npx -y knip
node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'typescript' imported from /Users/m.ivanov4/.npm/_npx/8d873e0e769cf1b4/node_modules/knip/dist/PrincipalFactory.js
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:887:9)
    at moduleResolve (node:internal/modules/esm/resolve:936:20)
    at defaultResolve (node:internal/modules/esm/resolve:1129:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.17.1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

One where npx knip works standalone, of course 😃

@splincode @webpro I ran into the same issue, in my case it helped to use a different typescript version than my version that was locally installed.

npx -p typescript@latest -p knip knip

šŸš€ This issue has been resolved in v5.4.0. See Release 5.4.0 for release notes.

Doesn’t --legacy-peer-deps mean no peer deps get auto installed, and therefore that break is expected?

I think the global install is depending on whatever people happen to have gotten into their global caches, which is unfortunate and I didn’t realize that npx would not be properly installing peer deps.

(Then again, it’s a little odd to use knip globally, becuase I would expect that my workspace typescript be used, not some random version set by knip).

Thanks for reporting this. Knip requires peer dependencies typescript and @types/node and I’m not sure why npx fails to find or install those.

Not sue how to reproduce. When I try this and knip is not globally available (i.e. knip or which knip err and nothing in npm ls -g has knip listed etc.), ā€œit works on my machineā€. Maybe it’s an old/specific version of npm?

You could try pnpm dlx knip or bunx knip too as a workaround.