使用实时服务器时,实时服务器不会缓存 JavaScript 代码
我的项目是基于 React.js/Babel.js 的。我确信我的代码没有错误,但实时服务器没有响应通过 JavaScript 所做的更改。我对 HTML 文件进行了更改,更改没有任何错误。当我对 JavaScript 文件进行更改时,它们却没有更改。
我尝试了以下选项,但问题仍然存在,并且浏览器拒绝显示代码上的更改:
- 停止/运行 Live 服务器
- 切换浏览器
- 删除浏览器缓存
- 删除 Live 服务器 IP Cookie
- 禁用/启用 Live Server
- 卸载/安装 Live Server
- 安装 Live - 服务器使用 NPM
- 检查审核包依赖关系是否存在安全漏洞 使用审计修复
- 运行 Live Server 的公共目录,其中 Babel JS 和 Index.html 被存储。
- 重置 Windows
以下是屏幕截图:
然后我尝试为公共目录 [live-server public] 运行 Live Server,结果显示了以下控制台结果:
Stackoverflow 不断显示此错误 [您的帖子似乎包含代码格式不正确的代码。] 因此我将代码上传到 Codepen [https://codepen.io/abbbas_alhashimi/pen/XWzQaJP]
请注意:当实时服务器运行“测试”时,浏览器中不会显示一条控制台消息。我也尝试更改字符串值,但浏览器始终显示旧版本的代码。
我希望我已经向您提供了帮助我解决此问题所需的所有信息。
先感谢您
My project is React.js/Babel.js based. I have no errors with my code which I'm certain of, but the live server isn't responding to changes made via JavaScript. I made changes to the HTML file, changes take place without any errors. When I make changes to the JavaScript file, they don't.
I tried the following options but the problem remained as is and the browser refuse to show changes on the code:
- Stop/Run Live server
- Switch browser
- Delete Browser Cache
- Delete the live server IP Cookies
- Disable/Enable Live Server
- Uninstall/install Live Server
- Install Live-server using NPM
- Checked Auditing package dependencies for security vulnerabilities
using audit fix - Running Live Server for the public directory where Babel JS and
Index.html is stored. - Reset Windows
Here's a Screenshot:
Then I tried running Live Server for the public directory [live-server public] and that showed me the following console result:
Stackoverflow keeps showing this error [Your post appears to contain code that is not properly formatted as code.] therefore I uploaded my code to Codepen [https://codepen.io/abbbas_alhashimi/pen/XWzQaJP]
Please note: There is a console message that isn't displayed in the browser when live-server is running "test". I tried changing string values as well, but the browser keeps showing the old version of the code.
I hope, I have given you all the information required to help me solve this issue.
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了!
您需要确保正确安装 Babel Presets 并将 JSX 使用 Babel 编译为 JavaScript。您可以使用以下脚本来阐明请求的编译文件、输出和预设。 babel src/app.js --out-file=public/scripts/app.js --presets=env,react。一旦服务器运行并编译,您应该让服务器主动编译 JSX,并且您的所有更改都会发生,而不会出现任何进一步的复杂情况。这可以通过在最后一个命令末尾添加 --watch 来完成,如下所示: babel src/app.js --out-file=public/scripts/app.js --presets=env,react --watch。
我希望我的人会发现我的解决方案有帮助。
I solved it!
You Need to make sure that Babel Presets are properly installed and compiling JSX with Babel into JavaScript. You could use the following script to clarify the requested compilation files, the output, and the presets.
babel src/app.js --out-file=public/scripts/app.js --presets=env,react
. Once the server is running and compiling, you should let the server actively compile JSX and all your changes will take place without any further complications. This can be done by adding --watch at the end of the last command to look like this:babel src/app.js --out-file=public/scripts/app.js --presets=env,react --watch
.I hope my someone will find my solution helpful.