potty / react-anchorme

⚓️ React component using Anchorme.js to detect urls and emails in a text and converts them into clickable HTML links.
MIT License
56 stars 7 forks source link

Production build: cannot read properties of undefined (reading 'list') #26

Open juiceo opened 9 months ago

juiceo commented 9 months ago

We have a strange issue using this lib, which is only reproducible in our production builds:

TypeError: Cannot read properties of undefined (reading 'list')
    at react-anchorme.esm.js:1:1275
    at react-anchorme.esm.js:1:1550
    at Object.useMemo (react-dom.production.min.js:184:189)
    at Er.useMemo (react.production.min.js:25:208)
    at react-anchorme.esm.js:1:1530
    at eK (react-dom.production.min.js:167:137)
    at s$ (react-dom.production.min.js:197:258)
    at Vge (react-dom.production.min.js:195:204)
    at dre (react-dom.production.min.js:194:176)
    at lbe (react-dom.production.min.js:297:71)
o$ @ react-dom.production.min.js:189

which I can pinpoint to line 16 in AnchorMe.tsx:

import React, { useCallback, useMemo } from 'react'
import anchorme from 'anchorme'

import { AnchorProps, LinkComponent } from './types'
import { Link } from './Link'

type Props = {
    children: string
    linkComponent?: LinkComponent
} & AnchorProps

const Anchorme = ({ children, ...rest }: Props) => {
    const text = children

    const parse = useCallback(() => {
        const matches = anchorme.list(text) // <- This right here
        if (matches.length === 0) return text

...

What gives? It's as if the anchorme package isn't bundled for production?

Environment:

juiceo commented 9 months ago

Was able to resolve the issue by downgrading react-anchorme to 3.0.0, so seems like there is something off with the 4.0.1 version at least 🤔