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

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

Open juiceo opened this issue 2 years ago • 1 comments

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:

  • Build system: Vite
  • react-anchorme version: 4.0.1
  • react version: 18.2.0

juiceo avatar Nov 29 '23 10:11 juiceo

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 🤔

juiceo avatar Nov 29 '23 10:11 juiceo