[英]AWS Amplify: DevTools failed to load SourceMap: Unexpected token < in JSON at position 0
I am getting several warnings when loading my website on Google Chrome similar to the following:在 Google Chrome 上加载我的网站时,我收到了一些类似于以下内容的警告:
DevTools failed to load SourceMap: Could not parse content for https://mywebsite.com/static/js/2.abcd1234.chunk.js.map: Unexpected token < in JSON at position 0
My webapp is a React application (create-react-app) deployed on AWS Amplify.我的 webapp 是部署在 AWS Amplify 上的 React 应用程序 (create-react-app)。 I do not get these warnings when running the app locally.在本地运行应用程序时,我没有收到这些警告。 How do I get rid of these warnings?我如何摆脱这些警告?
This is a problem caused by using react-router
with AWS amplify.这是将react-router
与 AWS amplify 一起使用导致的问题。 See this github issue .请参阅此 github 问题。 It suggests adding the following entry in the Rewrites and redirects
section of App settings in AWS Amplify:它建议在 AWS Amplify 的 App 设置的Rewrites and redirects
部分添加以下条目:
Source address:
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
Target address:
/index.html
Type:
200 (Rewrite)
To solve my problem, I added the map
extension to this regex:为了解决我的问题,我向这个正则表达式添加了map
扩展名:
Source address:来源地址:
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map)$)([^.]+$)/>
I checked my Rewrites and redirects settings and it was already configured as per the below answer by "roob" but also had json
at the end.我检查了我的重写和重定向设置,它已经按照“roob”的以下答案进行了配置,但最后还有json
。 I removed it to see if that helped.我将其删除以查看是否有帮助。 Either way, I still got the error.无论哪种方式,我仍然得到错误。
More research with a colleague and found another root cause.与同事进行更多研究,发现了另一个根本原因。 Answered here: AWS Amplify error: Failed to parse source map... file: Error: ENOENT: no such file or directory在这里回答: AWS Amplify error: Failed to parse source map... file: Error: ENOENT: no such file or directory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.