-
Notifications
You must be signed in to change notification settings - Fork 362
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
Cannot read property 'substr' of undefined #247
Comments
I'm seeing this same error here: https://github.com/mozilla/source-map/blob/master/lib/source-node.js#L95 For me, I can reproduce in an Angular 2 TypeScript file: THIS breaks:
THIS works:
|
Don't write two or more classes in the same ts file. I think it's a bug of 'source-map'. |
Manually applying this patch resolves this issue. |
Not only in Ionic-app. I also have the error on my Angular 4 app. When I run ng serve.
|
There's a patch you can try - see #257. Before merging it, though, I'd like a regression test, and I still don't know how to write one. If you have a recipe for reproducing (the simpler the better, and for best results really walk me through the setup), that would be super helpful. |
I can reproduce using the project angular-cache. If I try |
Got same error with Preact-based project. |
Isn't two or more classes in one ts-file valid? |
The fit of the issue is very simple, create other file exclusively your class! (e.g modal-item.ts) |
The issue is not limited to typescript definitions. You can reproduce not using typescript with [email protected] and webpack. |
What would help move this along is a way for me to reproduce it. The more canned the instructions, the better. Then I can try to reduce it to a test case. |
I created a repo that has a fairly simple reproduction of this issue: |
Heya, I've been digging into the error a bit more and I'm not sure that it's as easy as just applying #257 to fix it. Applying that fix can hide broken sourcemaps. In my case it came up when chaining sourcemaps, and having the error was a sign the sourcemap I was creating was incorrect. An easy way to check this is to incorrectly chain maps. If you have But you can just as easily chain I've prepared a simple reproduction of this. It doesn't include webpack or anything of the sort, just using the
Read through This repro also includes a version of http://sokra.github.io/source-map-visualization/ that was patched with #257 so you can visualize how the generated map doesn't look right. /cc @hansl |
Thanks @filipesilva |
Yes, thanks very much. |
@filipesilva IIUC this test case is creating an invalid chaining. My inclination is to say that in this situation, it's fine to yield a bad result. I suppose it would be better (if possible -- I have no idea) to throw an exception when creating the bad map rather than when reading it. @ganemone I looked at your example. Thank you. I'm still digging into this; but a simple test case loading preact's |
... but |
@tromey throwing a meaningful exception here would be fine with us. Alternatively, allowing a flag that silence the error would also be great. We could surround the sourcemaps handling into a try block, but that just means that we have to drop sourcemaps entirely. I'd say partial sourcemaps are better than no sourcemaps? This can be argued both ways. We have had people publishing invalid sourcemaps to npm that cannot be chained properly, so it's not just our code. |
Applying the propose |
Changing preact to use a newer version of rollup fixed the preact source map. |
@hansl I'm curious to know when you'd want to silently accept an invalid source map. I'm working on source map support in the Firefox DevTools. My first reaction is to just change the error message to be better. My reasoning is that, for DevTools users, showing an error message is somewhat actionable, whereas using an invalid source map is likely to yield weird behavior (sometimes, maybe not always -- but that seems worse) without any explanation. I wish there was a way to make the checking even more strict, like having some kind of hash that so that source/map mismatches could be immediately seen. |
If the user can derive information from it, even a partial sourcemap can be useful for, e.g. sourcemap visualization tools. Let's say you have 3 sources, BTW, I'm in favor of a "validation" function that can tell us in advance if a sourcemap is valid or not without applying it. I understand this is not necessarily complicated to code, but if it was part of this library would at least make it authoritative. I'm not arguing for ignoring the invalid symbols. I feel the issue here is that working with sourcemaps is complicated and there should be better tooling in place to help those libraries release proper working sourcemaps in the first place. But that's outside of this particular issue (and may just be a question of better documentation/educating developers instead of a technical solution). |
I wouldn't say that; just that if the source map is in valid, there's no reason to believe any of it is any good. So instead of helping the user, maybe what's happening is just utter confusion and wasted time. That's why I tend to think tools should give users error messages instead of just carrying on. But I get what you're saying. The situation isn't always that dire. And sometimes tools are broken. So maybe I will add a bypass. |
It's up to you really. We'll communicate to the user that some maps are missing (there'll be empty sourcemaps, basically :/ ) |
I second @hansl's suggestion of a validation function. It would be great to have a validator that we could add to our unit/e2e tests. I tried searching for such a thing and couldn't find anything besides https://github.com/ben-ng/sourcemap-validator which didn't seem to work. Perhaps I searched in the wrong places? It's important to define what a valid sourcemap is though. Some sourcemaps might be missing things (like @hansl's example) but others are just completely broken (like in the invalid chaining). I don't think these are the same from a usage point of view. With that in mind I think partial sourcemaps still have an use, while completely broken ones serve no purpose. No idea if it's possible to actually make this distinction though. |
Avoid calling substr on `undefined` in `fromStringWithSourceMap`. This can happen when passing in a source map that refers to lines past the end of the passed-in string -- caller error, but let's not die. Fixes mozilla#247
Avoid calling substr on `undefined` in `fromStringWithSourceMap`. This can happen when passing in a source map that refers to lines past the end of the passed-in string -- caller error, but let's not die. Fixes mozilla#247
Avoid calling substr on `undefined` in `fromStringWithSourceMap`. This can happen when passing in a source map that refers to lines past the end of the passed-in string -- caller error, but let's not die. Fixes mozilla#247
TypeError: Cannot read property 'substr' of undefined
at Function. (...\node_modules\webpack-sources\node_modules\source-map\lib\source-node.js:115:26)
Version: 0.5.6
This problem seems to be related to trying to parse a js file containing a long //# sourceMappingURL at the end. For example, by trying to use the typemoq library in an Angular 2 application, as per this SO issue:
http://stackoverflow.com/questions/40002699/typemoq-and-angular-cli-dont-work-together#comment67466029_40002699
If I delete the //# sourceMappingURL line from typemoq.js the source node loads fine.
The text was updated successfully, but these errors were encountered: