我正在做我的盖茨比项目,并尝试添加React Cookie Consent包。在安装并尝试实现它之后,我的站点崩溃了,用以下错误证明了我:
warn ./.cache/root.js
Attempted import error: 'BaseContext' is not exported from '@gatsbyjs/reach-router' (imported as 'BaseContext').我似乎找不到解决办法,也不知道为什么会这样。Localhost向我抛出了以下错误:
_gatsbyjs_reach_router__WEBPACK_IMPORTED_MODULE_2__.BaseContext is undefined欢迎任何帮助!谢谢您:)
发布于 2022-04-12 05:50:26
在尝试通过运行以下方式删除缓存文件夹时:
gatsby clean如果问题持续存在,请尝试绕过SSR限制,将以下内容添加到gatsby-node.js中
exports.onCreateWebpackConfig = ({actions, loaders, stage}) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /react-cookie-consent/,
use: loaders.null(),
},
],
}
})
}
};或者使用动态导入:
useEffect(() => {
(async () => {
const { getCookieConsentValue, Cookies } = await import('react-cookie-consent')
getCookieConsentValue('test')
Cookies.get()
})()
}, [])您可以在以下网址查看进一步的方法:https://github.com/Mastermindzh/react-cookie-consent/issues/136
https://stackoverflow.com/questions/71833838
复制相似问题