(精华)CodeSandbox部署服务器无法查看问题解决/全网唯一解

一、问题如下:

Couldn't connect to server

This means sandpack cannot connect to the runtime or your network is having some issues. Please check the network tab in your browser and try again. If the problem persists, report it via [email](mailto:hello@codesandbox.io?subject=Sandpack%20Timeout%20Error) or submit an issue on [GitHub.](https://github.com/codesandbox/sandpack/issues)

ENV: create-react-app
ERROR: TIME_OUT

二、背景

  在我的毕设中,使用的是nextjs框架。我希望像claude一样左边聊天,右边生成代码,专业词叫做交互式编辑器。经过询问claude3.7发现@codesandbox/sandpack-react这个库特别好用,样式也喜欢,效果如下:

但是,只有本地能运行,如果你跟我一样部署到服务器你会发现,报开头一样的错:

这个时候,我就去到该库的github源代码的issues处,翻遍很多条类似的问题仍旧找不到答案,所以只能从原理出发。

三、原因:Babel构建错误

通过分析控制台相关报错追踪发现,出错的位置位于npm包下的dist目录,并且存在内容未定义,初步判定构建错误

四、解决方案

1. 在依赖中加入@babel/runtime包

npm install @codesandbox/sandpack-react@latest @babel/runtime

2. 指定入口文件/index.js;

3. 降级@codesandbox/sandpack-react到稳定版本比如2.6.9

npm install @codesandbox/sandpack-react@2.6.9

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值