You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@rollup/plugin-babel causes SOURCEMAP_ERROR while reporting THIS_IS_UNDEFINED from unmapped generated helper code #2005
When Rollup reports THIS_IS_UNDEFINED for generated helper code that has no original source mapping, using @rollup/plugin-babel should not add extra SOURCEMAP_ERROR warnings.
Bare Rollup reports only THIS_IS_UNDEFINED for the same input.
Actual Behavior
With @rollup/plugin-babel in the pipeline, Rollup emits additional SOURCEMAP_ERROR warnings before the original THIS_IS_UNDEFINED warnings:
[onwarn] SOURCEMAP_ERROR src/index.js (1:17): Error when using sourcemap for reporting an error: Can't resolve original location of error.
[onwarn] THIS_IS_UNDEFINED src/index.js (1:17): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
[onwarn] SOURCEMAP_ERROR src/index.js (1:25): Error when using sourcemap for reporting an error: Can't resolve original location of error.
[onwarn] THIS_IS_UNDEFINED src/index.js (1:25): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
Steps to Reproduce
git clone https://github.com/shrinktofit/rollup-babel-sourcemap-bug.git
cd rollup-babel-sourcemap-bug
pnpm install
pnpm run build
For comparison, bare Rollup does not emit SOURCEMAP_ERROR:
pnpm run build:bare
Notes
The repro simulates TypeScript legacy decorator output:
The sourcemap intentionally has no mapping for generated line 1, representing compiler-generated helper code. The mapping starts at generated line 2.
Bare Rollup reports THIS_IS_UNDEFINED without SOURCEMAP_ERROR. Once @rollup/plugin-babel is added, the input sourcemap enters the sourcemap chain and Rollup tries to map the generated helper location back to an original source location. Since helper code has no original mapping, that remapping fails and produces noisy SOURCEMAP_ERROR warnings.
This shape appears in real projects when bundling TypeScript output that contains inline legacy decorator helpers and sourcemaps.
When Rollup then raises THIS_IS_UNDEFINED at 1:17, addLocationToLogProps calls getOriginalLocation on the sourcemap chain. That throws as soon as it hits a line with no segments, and the catch turns it into SOURCEMAP_ERROR. Bare Rollup never loads index.js.map, so there's no chain to walk and you only get the original warning.
Rollup has a test asserting exactly this behavior (test/function/samples/cannot-resolve-sourcemap-warning, a transform that returns mappings: '' and expects SOURCEMAP_ERROR before THIS_IS_UNDEFINED), so it looks intentional. If it should be quieter for valid-but-unmapped helper code, that's probably a change for rollup/rollup rather than this plugin.
Workarounds in the meantime, both checked against your repro:
Or pass inputSourceMap: false to babel(). The warnings go away, but your output map then points at the compiled index.js instead of original.ts, so I'd only do that if you don't need the chain.
Activity
RagedPanda commentedon Oct 22, 2026
Dug into this a bit. I don't think plugin-babel is doing anything wrong here. The warning comes from Rollup core.
Babel reads
index.js.map(inputSourceMapis on by default) and merges it, so its output map has nothing on line 1, same as the input:When Rollup then raises
THIS_IS_UNDEFINEDat 1:17,addLocationToLogPropscallsgetOriginalLocationon the sourcemap chain. That throws as soon as it hits a line with no segments, and the catch turns it intoSOURCEMAP_ERROR. Bare Rollup never loadsindex.js.map, so there's no chain to walk and you only get the original warning.Rollup has a test asserting exactly this behavior (
test/function/samples/cannot-resolve-sourcemap-warning, a transform that returnsmappings: ''and expectsSOURCEMAP_ERRORbeforeTHIS_IS_UNDEFINED), so it looks intentional. If it should be quieter for valid-but-unmapped helper code, that's probably a change for rollup/rollup rather than this plugin.Workarounds in the meantime, both checked against your repro:
onwarn:inputSourceMap: falsetobabel(). The warnings go away, but your output map then points at the compiledindex.jsinstead oforiginal.ts, so I'd only do that if you don't need the chain.