AWS Amplify:DevTools 无法加载 SourceMap:位置 0 JSON 中的意外标记 <
AWS Amplify: DevTools failed to load SourceMap: Unexpected token < in JSON at position 0
我在 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
我的 webapp 是部署在 AWS Amplify 上的 React 应用程序 (create-react-app)。当 运行 在本地应用程序时,我没有收到这些警告。我如何摆脱这些警告?
这是将 react-router
与 AWS amplify 一起使用导致的问题。参见 this github issue。它建议在 AWS Amplify 的应用程序设置的 Rewrites and redirects
部分添加以下条目:
Source address:
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
Target address:
/index.html
Type:
200 (Rewrite)
为了解决我的问题,我向这个正则表达式添加了 map
扩展:
源地址:
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map)$)([^.]+$)/>
我检查了我的 重写和重定向 设置,它已经按照“roob”的以下回答进行了配置,但最后还有 json
。我将其删除以查看是否有帮助。无论哪种方式,我仍然遇到错误。
与同事进行更多研究,发现了另一个根本原因。在这里回答:
AWS Amplify error: Failed to parse source map... file: Error: ENOENT: no such file or directory
我在 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
我的 webapp 是部署在 AWS Amplify 上的 React 应用程序 (create-react-app)。当 运行 在本地应用程序时,我没有收到这些警告。我如何摆脱这些警告?
这是将 react-router
与 AWS amplify 一起使用导致的问题。参见 this github issue。它建议在 AWS Amplify 的应用程序设置的 Rewrites and redirects
部分添加以下条目:
Source address:
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
Target address:
/index.html
Type:
200 (Rewrite)
为了解决我的问题,我向这个正则表达式添加了 map
扩展:
源地址:
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map)$)([^.]+$)/>
我检查了我的 重写和重定向 设置,它已经按照“roob”的以下回答进行了配置,但最后还有 json
。我将其删除以查看是否有帮助。无论哪种方式,我仍然遇到错误。
与同事进行更多研究,发现了另一个根本原因。在这里回答: AWS Amplify error: Failed to parse source map... file: Error: ENOENT: no such file or directory