PinataCloud / Pinata-SDK

Official SDK for the Pinata IPFS service
MIT License
271 stars 67 forks source link

Error while testing auth in next 14 app router #171

Closed meddhiaka closed 4 months ago

meddhiaka commented 4 months ago

Found this error while trying to test the pinata officiel sdk in next14 project,

./node_modules/@pinata/sdk/lib/pinata-sdk.js:24421:0
Module not found: Can't resolve 'fs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./lib/pinata.ts
./app/home/page.tsx

here is the code: page.tsx

"use client"
import { pinata } from '@/lib/pinata'
import React, { useEffect } from 'react'

function page() {
  useEffect(() => {
    pinata.testAuthentication()
      .then(r => {
        console.log(r)
        console.log("it is working")
      })
  }, [])

  return (
    <div>

    </div>
  )
}

export default page

and the module pinata.ts

import pinataSDK from '@pinata/sdk'

const pinata = new pinataSDK(process.env.PINATA_API_Key, process.env.PINATA_API_Secret)

export {
    pinata
}
stevedylandev commented 4 months ago

Hey there! The Pinata SDK is currently a Node.js only sdk, which means it can only be used server side. We will be looking into changing this in the future. In the meantime we do have an app router template which uses the API as a server side function you can check out: https://github.com/PinataCloud/pinata-app-router-starter