确认了版本是对的,写的 node 代码,返回的是 null,还有什么办法吗?Full 和 App 里的 app-service.map.map 都试过了
const fs = require("fs");
const { SourceMapConsumer } = require("source-map");
async function originalPositionFor(line, column) {
const sourceMapFilePath = "./sourcemap/__APP__/app-service.map.map";
const sourceMapConsumer = await new SourceMapConsumer(
JSON.parse(fs.readFileSync(sourceMapFilePath, "utf8"))
);
return sourceMapConsumer.originalPositionFor({
line,
column,
});
}
originalPositionFor(16879, 11266).then((res) => {
console.log(res);
});
➜ sourcemap node index.js
{ source: null, line: null, column: null, name: null }
appid 给下
const fs = require("fs");
const { SourceMapConsumer } = require("source-map");
async function originalPositionFor(line, column) {
const sourceMapFilePath = "./sourcemap/__APP__/app-service.map.map";
const sourceMapConsumer = await new SourceMapConsumer(
JSON.parse(fs.readFileSync(sourceMapFilePath, "utf8"))
);
return sourceMapConsumer.originalPositionFor({
line,
column,
});
}
originalPositionFor(5593 + 16879, 11266).then((res) => {
console.log(res);
});
我也遇到相同的情况,根据楼上的对话确认列号没问题,就写了个代码通过列号反向定位,我目前使用还行。通过关键字搜索锁定文件列表,再从程序推出的文件求交集查看文件,基本能锁定源代码位置。
// npm install vlq const vlq = require('vlq'); function analyze(sourceData/*sourceMap内容*/) { const source = typeof sourceData === 'string' ? JSON.parse(sourceData) : sourceData; const { mappings = '', sources = {} } = source; const lines = mappings.split(';'); let _oLine = 0; let _oCol = 0; let _sourceIndex = 0; return lines.reduce((map, line, idx) => { if (line) { let _col = 0; map[idx] = line.split(',').reduce((info, code) => { let [ col, sourceIndex, oLine, oCol ] = vlq.decode(code); col += _col; oLine += _oLine; oCol += _oCol; sourceIndex += _sourceIndex; info[col] = { line: oLine, col: oCol, file: sources[sourceIndex], }; _col = col; _oLine = oLine; _oCol = oCol; _sourceIndex = sourceIndex; return info; }, {}); } return map; }, {}); } function findWithCol(sourceData/* sourceMap内容 */, targetCol/* 列号 */) { const result = analyze(sourceData); const info = Object.create(null); Object.keys(result).forEach(line => { const cols = result[line]; Object.keys(cols).forEach(col => { if (col === String(targetCol)) { const target = cols[col]; if (!info[target.file]) { info[target.file] = [] } info[target.file].push(`${target.line}:${target.col},编译后文件位置:${line}:${col}`); } }); }); return info; }
我也遇到了这个问题,并且我加上了偏移量 5593 后 node解析还是null ,都是,
{ source: null, line: null, column: null, name: null }
我的代码报错信息是:
TypeError: Cannot read property \'XXXXX\' of null at https://usr/.../app-service.js:4892:28680 at https://usr/.../app-service.js:4892:12480 at https://usr/.../app-service.js:4853:15795
试过了 10485,28680 和 10446,15795 也都还是null