Open rbuckton opened 6 years ago
Actually, it also seems to stem from the fact that the first line of SourceMapGenerator.fromSourceMap
reads aSourceMapConsumer.sourceRoot
, but a SourceMapConsumer
for an index map does not have a sourceRoot
.
There is a workaround for this issue:
const consumer = await new sourcemap.SourceMapConsumer(map);
consumer.sourceRoot = null; // Workaround
const generator = sourcemap.SourceMapGenerator.fromSourceMap(consumer); // TypeError
However, there is still a TypeError due to another issue in the underlying implementation:
Error: "source.js" is not in the SourceMap.
at IndexedSourceMapConsumer.sourceContentFor (C:\dev\scratch\source-map-test\node_modules\source-map\lib\source-map-consumer.js:980:11)
at C:\dev\scratch\source-map-test\node_modules\source-map\lib\source-map-generator.js:82:42
at Array.forEach (<anonymous>)
at Function.fromSourceMap (C:\dev\scratch\source-map-test\node_modules\source-map\lib\source-map-generator.js:72:32)
at test (C:\dev\scratch\source-map-test\test.js:18:52)
at <anonymous>
It seems fromSourceMap
is calling sourceContentFor
without passing true
for the nullOnMissing
param.
I am also facing this:
92% chunk asset optimization 92% chunk asset optimization UglifyJSPlugin/node_modules/uglifyjs-webpack-plugin/node_modules/source-map/lib/source-map-consumer.js:20
return sourceMap.sections != null
^
TypeError: Cannot read property 'sections' of null
at new SourceMapConsumer (/node_modules/uglifyjs-webpack-plugin/node_modules/source-map/lib/source-map-consumer.js:20:19)
at UglifyJsPlugin.buildError (/node_modules/uglifyjs-webpack-plugin/dist/index.js:116:23)
at /node_modules/uglifyjs-webpack-plugin/dist/index.js:275:45
at Array.forEach (native)
at /node_modules/uglifyjs-webpack-plugin/dist/index.js:259:19
at step (/node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:90:11)
at done (/node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:99:22)
at /node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:105:15
at /node_modules/worker-farm/lib/farm.js:191:19
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
When calling
SourceMapGenerator.fromSourceMap
with aSourceMapConsumer
for an index map, the following error is thrown:test.js
The error seems to be due to a strict inequality (
!==
) check onsourceRoot
whereas all other checks againstsourceRoot
use loose inequality (!=
).