[英]react-scripts build: Failed to minify the code from this file: opentok.js:1310
[英]react-scripts build then serve is serving html, not the main.js file
我正在使用react-scripts
并成功运行npm run build
来生成build
文件夹。
然后,我通过运行serve -s build
来使用serve npm软件包在本地提供serve -s build
。
然后在5000端口上运行serve
,这很好。
当我访问位于localhost:5000
的页面时,页面停滞了,控制台main.975cb3de.js:1 Uncaught SyntaxError: Unexpected token <
出现以下错误main.975cb3de.js:1 Uncaught SyntaxError: Unexpected token <
。
我在控制台中打开main.975cb3de.js
文件,它正在尝试提供index.html
文件。
如果我清空浏览器缓存并重新加载页面,则可以正常加载。 每当我运行构建时都会发生这种情况。
我怀疑serve
库中有配置,但不太确定。
关于为什么它会尝试首次提供HTML以及如何解决此问题的任何想法?
我可以通过将serve
软件包更新到6.5.6
版并在运行serve时使用--cache
标志来解决此问题。
npm update -g serve
事实证明,将-s
标志与serve一起使用时,默认缓存为1天。 我不得不禁用此缓存,从而解决了该问题。
serve -s ./build --cache=-1
第二个命令对于解决此问题至关重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.