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

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

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