未验证 提交 d77bd944 编写于 作者: J JJ Kasper 提交者: GitHub

Fix `moduleId` not resolving correctly on Windows (#12584)

上级 13c94399
...@@ -26,8 +26,8 @@ export type OriginalStackFrameResponse = { ...@@ -26,8 +26,8 @@ export type OriginalStackFrameResponse = {
type Source = { map: () => RawSourceMap } | null type Source = { map: () => RawSourceMap } | null
function getOverlayMiddleware(options: OverlayMiddlewareOptions) { function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
async function getSourceById(protocol: string, id: string): Promise<Source> { async function getSourceById(isFile: boolean, id: string): Promise<Source> {
if (protocol === 'file:') { if (isFile) {
const fileContent: string | null = await fs const fileContent: string | null = await fs
.readFile(id, 'utf-8') .readFile(id, 'utf-8')
.catch(() => null) .catch(() => null)
...@@ -84,17 +84,14 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) { ...@@ -84,17 +84,14 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
return res.end() return res.end()
} }
const moduleUrl = new URL(frame.file) const moduleId: string = frame.file.replace(
const moduleId: string = /^(webpack-internal:\/\/\/|file:\/\/)/,
moduleUrl.protocol === 'webpack-internal:' ''
? // Important to use original file to retain full path structure. )
// e.g. `webpack-internal:///./pages/index.js`
frame.file.slice(20)
: moduleUrl.pathname
let source: Source let source: Source
try { try {
source = await getSourceById(moduleUrl.protocol, moduleId) source = await getSourceById(frame.file.startsWith('file:'), moduleId)
} catch (err) { } catch (err) {
console.log('Failed to get source map:', err) console.log('Failed to get source map:', err)
res.statusCode = 500 res.statusCode = 500
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册