无法安装 'next-stripe' 依赖项

Unable to install 'next-stripe' dependency

我正在试验新的 next-stripe API (https://github.com/ynnoj/next-stripe),因为它太新了,我还没有找到任何有用的文档来解释我的错误。

安装工具我 运行: yarn add next-stripe@beta 按照他们的建议。但是当我尝试像这样使用导入时:import NextStripe from 'next-stripe' 我收到 TypeScript 错误

"Could not find a declaration file for module 'next-stripe'. '/Users/user/example-app/medical/node_modules/next-stripe/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/next-stripe` if it exists or add a new declaration (.d.ts) file containing `declare module 'next-stripe';`"

在我 运行 命令“npm I --save...”之后,如错误所述,我在命令行中收到一系列错误,这些错误与找不到它有关(404 ).

在我的 package.json 中,我安装了这两个软件包:

"next": "^11.0.0",
"next-stripe": "^1.0.0-beta.9", 

所以它的某些版本确实安装了。

我将不胜感激任何帮助解决这个问题,如果这是一个常见问题,如果有任何关于使用哪个包号的具体建议。

编辑:当我添加 declare module 'next-stripe' 时;我收到错误

Invalid module name in augmentation. Module 'next-stripe' resolves to an untyped module at '/Users/user/Desktop/example-app/node_modules/next-stripe/index.js', which cannot be augmented.

您缺少包的类型


检查@types


检查是否有人为包创建了类型并安装该包,如下所示

npm i -D @types/next-stripe

Delcare 模块

如果@types/next-stripe不存在那么你需要自己将它声明为一个模块

  1. 声明模块 - 文件中只能声明一个模块

index.d.ts - 名称中必须包含 .d.ts

declare module 'next-stripe';
  1. 告诉打字稿包含文件

tsconfig.json

{
  "include": [
    "./index.d.ts"
  ]
}