Error: "migrate dev is not a prisma command." when calling `npx prisma migrate dev --preview-feature`

Error: "migrate dev is not a prisma command." when calling `npx prisma migrate dev --preview-feature`

当我运行以下命令时:

npx prisma migrate dev --preview-feature

我收到以下错误:

$ npx prisma migrate dev --preview-feature
npx: installed 600 in 26.334s
 ▸    migrate dev is not a prisma command.
 ▸    Perhaps you meant generate
 ▸    Run prisma help for a list of available commands.

Get in touch if you need help: https://slack.prisma.io
To get more detailed output, run $ set -x DEBUG "*"
(node:6096) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)

但是,prisma migrate dev 命令应该在 Prisma CLI 中可用。为什么这不起作用?

好吧,我想通了,我不小心调用了 Prisma 1 CLI,它可以作为 prisma package on npm

解决此问题的方法是确保作为 @prisma/cli package on npm is installed locally (see docs):

可用的 Prisma 2 CLI
npm install @prisma/cli --save-dev
# or
yarn add @prisma/cli --dev

那样npx will execute the right binary from the local node_modules folder

来自 npx 文档:

Executes <command> either from a local node_modules/.bin, or from a central cache, installing any packages needed in order for <command> to run.

By default, npx will check whether <command> exists in $PATH, or in the local project binaries, and execute that. If <command> is not found, it will be installed prior to execution.

Unless a --package option is specified, npx will try to guess the name of the binary to invoke depending on the specifier provided. All package specifiers understood by npm may be used with npx, including git specifiers, remote tarballs, local directories, or scoped packages.

如果由于某种原因没有获取本地二进制文件,您可以尝试将 prisma 脚本添加到您的 package.json:

{
  "scripts":  {
    "prisma": "prisma"
  }
}