I just experienced this issue myself. I found a solution that worked for me here
I haven't used Vue in some time and wanted to start a new project with VUE CLI Version 5, using TypeScript. However, every time I attempted to start the debugger, I received a message saying "We couldn't find a corresponding source location, but found some other files with the same name." After making adjustments to my launch.json, the furthest I would get is a breakpoint being hit in my app.js file.
The solution involves making changes to the vue.config.js file:
//vue.config.js
const { defineConfig } = require('@vue/cli-service')
const fs = require('fs');
const { SourceMapConsumer, SourceMapGenerator } = require('source-map');
module.exports = defineConfig({
configureWebpack() {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
plugins: [{
apply(compiler) {
compiler.hooks.thisCompilation.tap('Initializing Compilation', (compilation) => {
compilation.hooks.finishModules.tapPromise('All Modules Built', async (modules) => {
for (const module of modules) {
if (shouldSkipModule(module)) continue;
const pathWithoutQuery = module.resource.replace(/\?.*$/, '');
const sourceFile = fs.readFileSync(pathWithoutQuery).toString('utf-8');
const sourceMap = extractSourceMap(module);
sourceMap.sources = [pathWithoutQuery];
sourceMap.sourcesContent = [sourceFile];
sourceMap.mappings = await shiftMappings(sourceMap, sourceFile, pathWithoutQuery);
}
});
});
}
}]
};
function shouldSkipModule(module) {
const { resource = '' } = module;
if (!resource) return true;
if (/node_modules/.test(resource)) return true;
if (!/\.vue/.test(resource)) return true;
if (!/type=script/.test(resource)) return true;
if (!/lang=ts/.test(resource)) return true;
if (isMissingSourceMap(module)) return true;
return false;
}
function isMissingSourceMap(module) {
return !extractSourceMap(module);
}
function extractSourceMap(module) {
if (!module['_source']) return null;
return module['_source']['_sourceMap'] ||
module['_source']['_sourceMapAsObject'] ||
null;
}
async function shiftMappings(sourceMap, sourceFile, sourcePath) {
const indexOfScriptTag = getIndexOfScriptTag(sourceFile);
const shiftedSourceMap = await SourceMapConsumer.with(sourceMap, null, async (consumer) => {
const generator = new SourceMapGenerator();
consumer.eachMapping((mapping) => {
const {
generatedColumn,
generatedLine,
originalColumn,
originalLine,
} = mapping;
let original = mapping.original;
let name = mapping.name;
let source = sourcePath;
if (originalLine === null || originalColumn === null) {
name = null;
source = null;
}
else {
original = {
column: originalColumn,
line: originalLine + indexOfScriptTag,
};
}
generator.addMapping({
generated: {
column: generatedColumn,
line: generatedLine,
},
original,
source,
name
});
});
return generator.toJSON();
});
return shiftedSourceMap.mappings;
}
function getIndexOfScriptTag(sourceFile) {
const lines = sourceFile.match(/.+/g);
let indexOfScriptTag = 0;
for (const line of lines) {
++indexOfScriptTag;
if (/<script/.test(line)) break;
}
return indexOfScriptTag;
}
},
})
Finally, alter your launch.json, where "my-vue-project" is the name of your project
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch", //launch
"name": "vuejs: chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
"webpack://my-vue-project/./src/*": "${webRoot}/src/*"
}
}
]
}
The repo looked to have a slight error.