William Ackman
William Ackman

Reputation: 33

Unable to install 'next-stripe' dependency

I am experimenting with the new next-stripe API (https://github.com/ynnoj/next-stripe) and because it is so new I have not found any usable documentation to my error.

To install the tool I ran: yarn add next-stripe@beta as they recommend. But when I try and use the import like so: import NextStripe from 'next-stripe' I receive the TypeScript error

"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';`"

After I run the command "npm I --save..." as the error mentions, I get a series of errors in the command line which have to do with it not being found (404).

In my package.json I have these two packaged installed:

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

So some version of it did clearly install.

I would appreciate any assistance getting this up, and if there are any specific recommendations for which package number to use if this is a common issue.

EDIT: When I add declare module 'next-stripe'; I get the error

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.

Upvotes: 1

Views: 176

Answers (1)

Sean W
Sean W

Reputation: 6638

You're missing the types for the package


Check @types


Check is someone has made the types for the package and install that package like the following

npm i -D @types/next-stripe

Delcare module

If @types/next-stripe don't exist then you need to declare it as a module yourself

  1. Declare the module - only one module can be declared in the file

index.d.ts - must contain .d.ts in the name

declare module 'next-stripe';
  1. Tell typescript to include the file

tsconfig.json

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

Upvotes: 0

Related Questions