NextJS 13集成Sanity报错:TypeError: 无法读取undefined的call属性
Sanity Studio 加载报错排查方案
尝试加载Sanity Studio时出现模块加载报错,调用栈信息如下:
Call Stack options.factory file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/webpack.js (722:31) __webpack_require__ /_next/static/chunks/webpack.js (37:33) fn file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/webpack.js (377:21) eval node_modules\next\dist\compiled\react\cjs\react-jsx-dev-runtime.development.js (17:12) eval node_modules\next\dist\compiled\react\cjs\react-jsx-dev-runtime.development.js (1328:3) ./node_modules/next/dist/compiled/react/cjs/react-jsx-dev-runtime.development.js file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/app/studio/[[...index]]/page.js (5098:1) options.factory /_next/static/chunks/webpack.js (722:31) __webpack_require__ file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/webpack.js (37:33) fn /_next/static/chunks/webpack.js (377:21) eval node_modules\next\dist\compiled\react\jsx-dev-runtime.js (6:2) ./node_modules/next/dist/compiled/react/jsx-dev-runtime.js file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/app/studio/[[...index]]/page.js (5120:1) options.factory /_next/static/chunks/webpack.js (722:31) __webpack_require__ file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/webpack.js (37:33) fn /_next/static/chunks/webpack.js (377:21) eval webpack-internal:///./app/studio/[[...index]]/page.tsx (5:79) ./app/studio/[[...index]]/page.tsx file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/app/studio/[[...index]]/page.js (5001:1) options.factory /_next/static/chunks/webpack.js (722:31) __webpack_require__ file:///C:/Users/tirfa/Projects/nluz-blog/.next/static/chunks/webpack.js (37:33) fn /_next/static/chunks/webpack.js (377:21) __webpack_require__ node_modules\next\dist\client\app-index.js (26:16) eval node_modules\next\dist\compiled\react-server-dom-webpack\client.js (106:0)
排查及解决步骤:
- 清理Next.js缓存:执行
next clean命令,或手动删除项目根目录下的.next文件夹后重新构建 - 校验依赖兼容性:检查
package.json中next、sanity、react、react-dom的版本,确保互相兼容(建议参考Sanity官方文档指定的版本范围) - 重装依赖:删除
node_modules文件夹和package-lock.json(或yarn.lock),再执行npm install(或yarn install)重新安装所有依赖 - 检查Studio页面代码:确认
app/studio/[[...index]]/page.tsx中的初始化代码符合规范,比如正确调用defineConfig和Studio组件,没有语法错误或导入错误 - 临时关闭React严格模式:在
next.config.js中设置reactStrictMode: false,排查是否为严格模式下的兼容性问题
内容的提问来源于stack exchange,提问作者Nafukgt C2
相关产品推荐
相关产品推荐

