【问题标题】:parcel serve returns index.html for SourceMap requests and non existent urlsparcel serve 为 SourceMap 请求和不存在的 url 返回 index.html
【发布时间】:2021-06-18 11:14:26
【问题描述】:

使用 parcel 设置的普通 typescript 开发环境。

我在浏览器(Edge/Chrome)中没有 SourceMap:

DevTools failed to load SourceMap: Could not parse content for http://localhost:1234/index.7cacc1f4.js.map: Unexpected token < in JSON at position 0

页面加载后的包裹服务日志:

$ parcel serve ./src/index.html --log-level verbose
ℹ️ Server running at http://localhost:1234
✨ Built in 3.15s
@parcel/reporter-dev-server: Request: localhost:1234/
@parcel/reporter-dev-server: Request: localhost:1234/index.7cacc1f4.js
@parcel/reporter-dev-server: Request: localhost:1234/index.7cacc1f4.js.map
@parcel/reporter-dev-server: Request: localhost:1234/favicon-32x32.232ca4f5.png

SourceMap 文件位于 dist:

$ ls dist
__                              favicon-32x32.232ca4f5.png      index.453c97a0.js.map
apple-touch-icon.8e36bc09.png   favicon-32x32.a91f4dac.png      index.7cacc1f4.js
apple-touch-icon.e80caf23.png   index.031565ba.js               index.7cacc1f4.js.map
favicon-16x16.bc10cd1f.png      index.031565ba.js.map           index.html
favicon-16x16.d41cdce3.png      index.453c97a0.js

似乎parcel serve 正在返回索引页面而不是 SourceMaps:

$ curl -v localhost:1234/index.7cacc1f4.js.map 
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 1234 (#0)
> GET /index.7cacc1f4.js.map HTTP/1.1
> Host: localhost:1234
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, HEAD, PUT, PATCH, POST, DELETE
< Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Content-Type
< Content-Length: 630
< Content-Disposition: inline; filename="index.html"
< Accept-Ranges: bytes
< Last-Modified: Sun, 21 Mar 2021 17:09:09 GMT
< Content-Type: text/html; charset=utf-8
< Date: Sun, 21 Mar 2021 17:13:40 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
<!DOCTYPE html>

<html lang="en">
  [....]
</html>
* Connection #0 to host localhost left intact
* Closing connection 0

以上curl的包裹日志:

@parcel/reporter-dev-server: Request: localhost:1234/index.7cacc1f4.js.map

包裹版本:2.0.0-beta.2

奇怪的是 parcel serve 不返回 404 只是在找不到页面时重定向到索引?

@parcel/reporter-dev-server: Request: localhost:1234/asfsdfs.x
@parcel/reporter-dev-server: Request: localhost:1234/index.7cacc1f4.js
@parcel/reporter-dev-server: Request: localhost:1234/index.7cacc1f4.js.map
@parcel/reporter-dev-server: Request: localhost:1234/favicon-32x32.232ca4f5.png
@parcel/reporter-dev-server: Request: localhost:1234/__/static/site.webmanifest

【问题讨论】:

  • 我也遇到了同样的问题,如果找到解决办法我会告诉你的

标签: javascript typescript source-maps parceljs


【解决方案1】:

这是 parcel 2 中的一个错误,但已在当前的夜间构建中修复: https://github.com/parcel-bundler/parcel/issues/6078

【讨论】:

  • 谢谢@markus 问题的其他部分是否相同? IE。找不到页面上的 404。由于这些问题,我切换到了 webpack
  • 我没有检查,但可能是因为带有客户端路由的 SPA(包括客户端 404 处理)。如果您打算进行服务器端路由,您可能希望在开发模式下运行自己的服务器,并且不要依赖 parcel / webpack 开发服务器行为。
猜你喜欢
  • 2022-12-24
  • 2012-04-05
  • 2018-09-22
  • 2018-05-18
  • 1970-01-01
  • 1970-01-01
  • 2017-02-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多