Estaba trabajando en mi proyecto Gatsby e intenté agregar el paquete React Cookie Consent . Después de instalarlo e intentar implementarlo, mi sitio se descompuso, probándome con este error:
warn ./.cache/root.js Attempted import error: 'BaseContext' is not exported from '@gatsbyjs/reach-router' (imported as 'BaseContext').Parece que no puedo encontrar una solución, ni sé por qué está sucediendo. Localhost me arroja este error:
_gatsbyjs_reach_router__WEBPACK_IMPORTED_MODULE_2__.BaseContext is undefined¡Cualquier ayuda es bienvenida! Gracias :)
Al intentar eliminar la carpeta de caché ejecutando:
gatsby clean Si el problema persiste, intente omitir la limitación de SSR agregando lo siguiente a su gatsby-node.js :
exports.onCreateWebpackConfig = ({actions, loaders, stage}) => { if (stage === "build-html") { actions.setWebpackConfig({ module: { rules: [ { test: /react-cookie-consent/, use: loaders.null(), }, ], } }) } };O usando una importación dinámica:
useEffect(() => { (async () => { const { getCookieConsentValue, Cookies } = await import('react-cookie-consent') getCookieConsentValue('test') Cookies.get() })() }, [])Puede consultar otros enfoques en:https://github.com/Mastermindzh/react-cookie-consent/issues/136