react-tweet icon indicating copy to clipboard operation
react-tweet copied to clipboard

TypeError: Cannot read properties of undefined (reading 'error')

Open kjj9 opened this issue 2 years ago • 6 comments

Hi im using react-tweet with next js 14, app router. This is my code for component:

import { Suspense } from "react"
import { TweetSkeleton, Tweet } from "react-tweet"
import { getTweet as _getTweet } from "react-tweet/api"
import type { TwitterEmbedProps } from "@/types"

export const TwitterEmbed = ({ twitterAttrs }: TwitterEmbedProps) => {
	const { url } = twitterAttrs
	const id = url.split("/").pop() // Extract the post ID from the URL

	if (!id) {
		return <div>Invalid Tweet URL</div>
	}
	console.log(id)
	return (
		<Suspense fallback={<TweetSkeleton />}>
			<Tweet id={id} />
		</Suspense>
	)
}

It was working fine for while, now it stoped. I didnt do any changes that should broke it.

TypeError: Cannot read properties of undefined (reading 'error')
    at fetchTweet (webpack-internal:///(rsc)/./node_modules/react-tweet/dist/api/fetch-tweet.js:65:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getTweet (webpack-internal:///(rsc)/./node_modules/react-tweet/dist/api/get-tweet.js:10:43)
    at async TweetContent (webpack-internal:///(rsc)/./node_modules/react-tweet/dist/tweet.js:17:24)

Changing id to static one, just to see if is something wrong with id variable still resultate with this error as above.

kjj9 avatar Oct 15 '24 16:10 kjj9

Same issue here! This error started showing very recently, and seems to be happening only locally.

FilipPano avatar Oct 15 '24 18:10 FilipPano

yeah i can confirm that is only localy :) strange thing since it shouldnt block ip request locally. Is there solution for it? @FilipPano are you on static IP?

kjj9 avatar Oct 16 '24 12:10 kjj9

yeah i can confirm that is only localy :) strange thing since it shouldnt block ip request locally. Is there solution for it? @FilipPano are you on static IP?

I am using a dynamic IP.

FilipPano avatar Oct 16 '24 12:10 FilipPano

issue fixed by self. still don't know what was cause.

kjj9 avatar Oct 21 '24 15:10 kjj9

I started seeing this error recently from:

  • Next.js app API endpoint running locally: 200
  • Next.js app API endpoint running at (Netlify): 200
  • Next.js app API endpoint running at (Vercel): 404
  • Cloudflare Worker (deployed & local): 500

donpark avatar Dec 23 '24 00:12 donpark

this was also breaking for me in an OpenNext app on Cloudflare, did a little tinkering and I think it's because Node normally sends a default user-agent (appears to be node now, previously undici https://github.com/nodejs/undici/issues/2306) and Cloudflare's fetch doesn't. my workaround was just adding a user-agent in fetch options, e.g.

<Tweet
     id="<some-tweet-id>"
     fetchOptions={{
       headers: {
         "User-Agent": "node",
        },
     }}
/>

robertf224 avatar Oct 22 '25 01:10 robertf224