Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
getSource
✓ import getSource from 'get-source'
✗ import { getSource } from 'get-source'
This is the default export, primarily used for the synchronous API. Avoid named import or CommonJS require().
getSource.async
✓ import getSource from 'get-source'; const asyncSource = getSource.async;
✗ import { async } from 'get-source'
The asynchronous API is a property of the default export, not a separate named export. It returns awaitable Promises.
getSource.resetCache
✓ import getSource from 'get-source'; getSource.resetCache(); getSource.async.resetCache();
✗ import { resetCache } from 'get-source'
Cache reset functions are properties of the respective sync/async APIs. There are separate caches for sync and async operations.
Demonstrates fetching a source-mapped file asynchronously and resolving a specific line/column to its original source location, including basic error handling.
import getSource from 'get-source';
import fs from 'fs';
import path from 'path';
// Simulate a minified file and its sourcemap for demonstration
const minifiedCodePath = path.resolve('./dist/index.min.js');
const minifiedMapPath = path.resolve('./dist/index.min.js.map');
const originalCodePath = path.resolve('./src/index.js');
// In a real scenario, these files would exist or be fetched from a URL
fs.mkdirSync(path.dirname(minifiedCodePath), { recursive: true });
fs.writeFileSync(originalCodePath, 'console.log("Hello original source!");\nconst sum = (a, b) => a + b;');
fs.writeFileSync(minifiedCodePath, 'console.log("Hello minified!"); var a = 1, b = 2; console.log(a+b); //# sourceMappingURL=index.min.js.map');
fs.writeFileSync(minifiedMapPath, JSON.stringify({
version: 3,
file: 'index.min.js',
sources: ['../src/index.js'],
sourcesContent: ['console.log("Hello original source!");\nconst sum = (a, b) => a + b;'],
names: [],
mappings: 'AAAA,aAAa;AAAb;AAAA,IAAM,KAAK,GAAG,IAAM,IAAI,EAAE,CAAC,GAAE,CAAC,MAAMA,EAAE,CAAC;AAAA,IAAM,MAAM,GAAG,CAAC,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAAA,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;AAAA,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,GAAE,MAAM,CAAC;'
}));
async function run() {
try {
// Fetch the minified file and its sourcemap asynchronously
const file = await getSource.async(minifiedCodePath);
console.log(`Fetched file: ${file.path}`);
console.log(`Minified text: ${file.text.substring(0, 50)}...`);
// Resolve a location in the minified file to its original source
// Example: The 'console.log(a+b)' statement is around line 1, column 50 in minified.
const location = await file.resolve({ line: 1, column: 50 });
if (location && location.sourceFile) {
console.log('\nResolved original location:');
console.log(` Original File: ${location.sourceFile.path}`);
console.log(` Original Line: ${location.line}`);
console.log(` Original Column: ${location.column}`);
console.log(` Original Code: ${location.sourceLine}`);
} else {
console.log('Could not resolve location.');
if (file.error) console.error('Error during fetch:', file.error);
}
} catch (e) {
console.error('An error occurred:', e);
} finally {
// Clean up created files
fs.unlinkSync(minifiedCodePath);
fs.unlinkSync(minifiedMapPath);
fs.unlinkSync(originalCodePath);
fs.rmdirSync(path.dirname(minifiedCodePath));
fs.rmdirSync(path.dirname(originalCodePath));
}
}
run();
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use CommonJS `require()` syntax to import `get-source` in a Node.js environment where it is treated as an ES Module.
fixUse ES Module `import` syntax: `import getSource from 'get-source';` in your JavaScript files. Ensure your `package.json` has `"type": "module"` or your file is named `.mjs`.
TypeError: Cannot read properties of undefined (reading 'sourceLine')
Attempting to access properties of the `location` object returned by `file.resolve()` without checking if `location` itself is valid or if `location.sourceFile` exists, often because the original location could not be resolved (e.g., due to an invalid input line/column or malformed sourcemap).
fixAlways verify the returned `location` and its `sourceFile` property before accessing sub-properties: `const location = await file.resolve({ line: 1, column: 8 }); if (location && location.sourceFile) { console.log(location.sourceLine); } else { console.error('Could not resolve location.'); }` Audit
Dependencies
No dependency data recorded yet.