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.
RawSource
✓ import { RawSource } from 'webpack-sources'
✗ const RawSource = require('webpack-sources').RawSource
ESM and CJS both supported; named import preferred. Note the plural 'sources'.
OriginalSource
✓ import { OriginalSource } from 'webpack-sources'
Used to represent original source code with name.
SourceMapSource
✓ import { SourceMapSource } from 'webpack-sources'
For source code with existing source map.
ConcatSource
✓ import { ConcatSource } from 'webpack-sources'
✗ import { ConcatSource } from 'webpack'
ConcatSource is part of webpack-sources, not directly from webpack package.
CachedSource
✓ import { CachedSource } from 'webpack-sources'
Caches source/map/hash for repeated access.
PrefixSource
✓ import { PrefixSource } from 'webpack-sources'
Prepends a string to the wrapped source.
ReplaceSource
✓ import { ReplaceSource } from 'webpack-sources'
Allows targeted replacements in the source.
Demonstrates creating various Source types (RawSource, ConcatSource, OriginalSource, SourceMapSource, CachedSource) and accessing their source, size, and map methods.
import { RawSource, ConcatSource, OriginalSource, SourceMapSource } from 'webpack-sources';
import { SourceNode } from 'source-map'; // for demonstration
// Create a simple RawSource
const raw = new RawSource('console.log("hello world");');
console.log('source:', raw.source());
console.log('size:', raw.size());
// Concat multiple sources
const concat = new ConcatSource();
concat.add(new RawSource('var x = 1;\n'));
concat.add(new OriginalSource('var y = 2;\n', 'file2.js'));
console.log('concat source:', concat.source());
// SourceMapSource with identity mapping
const rawSource = 'var a = 1;';
const sourceMap = {
version: 3,
file: 'file.js',
sources: ['file.js'],
mappings: 'AAAA',
names: [],
sourcesContent: [rawSource]
};
const sms = new SourceMapSource(rawSource, 'file.js', sourceMap);
console.log('map:', sms.map());
// CachedSource for repeated reads
import { CachedSource } from 'webpack-sources';
const cached = new CachedSource(raw);
console.log('cached source:', cached.source()); // identical to raw
Errors
Common errors & fixes
TypeError: (intermediate value).source is not a function
Trying to call .source() on a source object that is actually a string or a raw module object from webpack compilation
fixVerify the object is an instance of a Source class: `if (source instanceof Source) { source.source(); }` Cannot read properties of undefined (reading 'source')
Accessing .source() on a source that is undefined or null, often from webpack compilation.
fixCheck that the source is defined before calling methods: `if (source) { source.source(); }` The 'sourceMap' property must be an object, string, or Buffer
Passing an invalid type for the sourceMap parameter to SourceMapSource constructor (e.g., number or boolean).
fixEnsure sourceMap is a valid SourceMap object (with version, sources, mappings), a JSON string, or a Buffer.
Audit
Dependencies
@types/nodeoptionalTypeScript definitions reference Node.js Buffer type