-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in preprocessor sourcemapping: "Cannot read property 'length' of undefined" #5722
Comments
My analysis so far: Update: This is certainly not the exact right fix, but adding this in the Svelte
|
omg thank you |
it's giving me |
Then your Node version is too old to support that syntax. You're probably better off just using Svelte 3.29 for now. |
Phew, glad I'm not alone. Also seems to be originating from |
I'm using Svelte 3.17.3 ...... |
If you're seeing this bug, you're using Svelte 3.30. https://bytearcher.com/articles/semver-explained-why-theres-a-caret-in-my-package-json/ |
It was explained: https://bytearcher.com/articles/semver-explained-why-theres-a-caret-in-my-package-json/ That The method this bug refers to did not exist until 3.30, which means you're either using 3.30 or encountering a different issue. |
Damn I didn't known it did that, thank you and sorry for being arrogant :/ |
thanks for the bug ; )
postcss is using this one problem is, this one cannot produce "decoded" mappings
yes, that will fix the problem, at the cost of a slightly slower compile processed.map = processed.map.toJSON(); the fastest solution is to fork the // not tested but "im feeling lucky"
import { compareByGeneratedPositionsInflated } from 'source-map/lib/util';
if (processed.map.constructor.name == 'SourceMapGenerator') {
/**
* patch function _serializeMappings()
* to return mappings in "decoded" format
*/
processed.map._serializeMappings = function () {
let previousGeneratedLine = 1;
let result = [[]];
let resultLine;
let resultSegment;
let mapping;
// optimized
const sourceIdx = this._sources.toArray().reduce((acc, val, idx) => (acc[val] = idx, acc), {});
const nameIdx = this._names.toArray().reduce((acc, val, idx) => (acc[val] = idx, acc), {});
const mappings = this._mappings.toArray();
resultLine = result[0];
for (let i = 0, len = mappings.length; i < len; i++) {
mapping = mappings[i];
if (mapping.generatedLine > previousGeneratedLine) {
while (mapping.generatedLine > previousGeneratedLine) {
result.push([]);
previousGeneratedLine++;
}
resultLine = result[mapping.generatedLine - 1]; // line is one-based
} else if (i > 0) {
if (
!compareByGeneratedPositionsInflated(mapping, mappings[i - 1])
) {
continue;
}
}
resultLine.push([mapping.generatedColumn]);
resultSegment = resultLine[resultLine.length - 1];
if (mapping.source != null) {
resultSegment.push(...[
//this._sources.indexOf(mapping.source),
sourceIdx[mapping.source], // optimized
mapping.originalLine - 1, // line is one-based
mapping.originalColumn
]);
if (mapping.name != null) {
resultSegment.push(
//this._names.indexOf(mapping.name)
nameIdx[mapping.name] // optimized
);
}
}
}
return result;
}
// call the patched function to get a "decoded" sourcemap
processed.map = processed.map.toJSON();
} now who said monkey-patching is bad? ; ) edit: optimized indexOf to cache-object |
I'm guessing the correct fix here is probably to detect malformed source maps from preprocessors and log an appropriate error for the user. |
agree with @halfnelson, where svelte should handle malformed sourcemaps better with an appropriate error, and an actual fix the sourcemap would have to come from the upstream, postcss svelte preprocessor |
While this is true, I think we should also be pragmatic and handle this specific case because I don't think upstream will just change this , others may even rely on this specific behavior. |
"malformed" .. these are not malformed, but in a different "decoded" format, which is still better than getting encoded mappings (these must be decoded for remapping, which is sloooow, why there should be a warning when svelte receives encoded mappings) we already accept one "decoded" format (the "dense array" format that remapping supports), why not support another one? its not like there are millions of formats that we all must support .. i thought svelte people care about performance? (or when did the trolls take over?) |
Is there no standard decoded format? Are you saying that changing |
If it's from source-map I doubt you'll get it merged upstream, it wasn't updated in over a year, the project is kind of "finished" it seems. |
no. the spec only defines the encoded format the "dense array" format, as produced by magic-string (etc) SourceMapGenerator has a different format these formats are both not ideal for remapping
no, that function is needed to produce the encoded format but then, that format is not specified, and only a de-facto-standard monkey-patching the if monkey-patching is too dirty, we could fork the toJSON method function SourceMapGenerator_serializeMappings() {
// see my 2nd last post
}
function SourceMapGenerator_toJSON() {
const map = {
version: this._version,
sources: this._sources.toArray(),
names: this._names.toArray(),
// this is the only diff
//mappings: this._serializeMappings()
mappings: SourceMapGenerator_serializeMappings.apply(this)
};
if (this._file != null) {
map.file = this._file;
}
// these are probably not needed
if (this._sourceRoot != null) {
map.sourceRoot = this._sourceRoot;
}
if (this._sourcesContents) {
map.sourcesContent = this._generateSourcesContent(
map.sources,
map.sourceRoot
);
}
return map;
}
if (processed.map.constructor.name == 'SourceMapGenerator') {
processed.map = SourceMapGenerator_toJSON.apply(processed.map)
} |
Could we use your |
yes, of course i would keep the the test could be changed to if (
processed.map._mappings &&
processed.map.constructor.name == 'SourceMapGenerator'
) {
// import decoded mappings from mozilla/source-map |
Same issue here |
Solved with |
This should be fixed in 3.30.1 - we now support source maps created by |
Describe the bug
The new preprocessor sourcemapping feature seems to sometimes cause errors (CC @halfnelson @milahu)
Logs
To Reproduce
git clone [email protected]:babichjacob/sapper-postcss-template.git
Upgrade to svelte 3.30 and rollup-plugin-svelte 7 following the upgrade guide (example of that here: sveltejs/sapper-template#289)
sourcemap = false -> no error
sourcemap = "inline" -> that error
sourcemap = true -> that error
Severity
Several people have reported this issue on Discord. It seems to happen relatively frequently
The text was updated successfully, but these errors were encountered: