Skip to content
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

TypeError in @ampproject/remapping with esbuild 0.24.2 + #200

Closed
alan-agius4 opened this issue Jan 24, 2025 · 6 comments
Closed

TypeError in @ampproject/remapping with esbuild 0.24.2 + #200

alan-agius4 opened this issue Jan 24, 2025 · 6 comments

Comments

@alan-agius4
Copy link

[error] TypeError: Cannot read properties of undefined (reading 'map')
    at originalPositionFor (\node_modules\@ampproject\remapping\dist\remapping.umd.js:77:21)
    at originalPositionFor (\node_modules\@ampproject\remapping\dist\remapping.umd.js:88:16)
    at traceMappings (\node_modules\@ampproject\remapping\dist\remapping.umd.js:56:30)
    at remapping (\node_modules\@ampproject\remapping\dist\remapping.umd.js:196:30)
    at transformWithBabel (\node_modules\@angular\build\src\tools\esbuild\i18n-inliner-worker.js:133:45)
    at async inlineLocale (\node_modules\@angular\build\src\tools\esbuild\i18n-inliner-worker.js:35:20)
    at async \node_modules\piscina\dist\worker.js:144:26

Steps to Reproduce

https://stackblitz.com/edit/stackblitz-starters-xnpd219g?file=index.js

Root Cause

Upon investigation, the issue appears to stem from the upgrade of esbuild from 0.24.0 to 0.24.2.

According to the esbuild changelog, the breaking change was introduced in version 0.24.1, as shown below:
Release Notes

It appears this is an intentional change in esbuild, which may require adjustments in @ampproject/remapping.

Expected Behavior

The application should work seamlessly with esbuild@0.24.2 without encountering a TypeError.

Actual Behavior

The application fails with a TypeError in @ampproject/remapping.

Originally posted by @mattlewis92 in #29465

@meriturva
Copy link

I'm so sorry to write here but I just would like to know if the PR will be merged and a new version released in the future.
We have to make a decision about disabling or keep source map enabled on few applications or get stuck on Angular v19.0.
Thanks.

@griest024
Copy link

@meriturva I suggest you override the esbuild version as described in this comment. It worked for us.

@meriturva
Copy link

@griest024 we have just disabled sourcemap generation as a workaround. Override version is not a feasible solution for all the enterprise projects I follow. On the big one project, we are still on Angular v19.0.

Thanks!

@alan-agius4 alan-agius4 changed the title TypeError in @ampproject/remapping with esbuild 0.24.2 TypeError in @ampproject/remapping with esbuild 0.24.2 + Feb 13, 2025
@jridgewell
Copy link
Collaborator

The stackblitz is erroring at a different location than the OP's stack trace:

        const source = rootSources[segment[1]];
        traced = originalPositionFor(
          source,
          segment[2],
          segment[3],
          segment.length === 5 ? rootNames[segment[4]] : ''
        );

Here, rootSources (constructed from the map's sources field) is an array of 16 items, segment[1] is 16, so we're doing rootSources[16] and getting undefined. Passing undefined to originalPositionFor will cause an error.

But this isn't remapping's fault, it's invalid for a source map to reference a 17th (index 16) source and only include 16 sources. From the sourcemap spec 9.a.iii.14:

If any of sourceIndex, originalLine, or originalColumn are less than 0, or if sourceIndex is greater than or equal to sources’s size, optionally report an error.

@jridgewell
Copy link
Collaborator

Looking at the the esbuild code, what it's calling "null entries" seem to be 1-length mappings:

If you scan remapping's codebase (or trace-mapping and gen-mapping), you'll see we already handle 1-length mappings. This isn't a new addition to source maps, just a new build tool producing them (Babel and Closure will too).

  • // 1-length segments only move the current generated column, there's no source information
    // to gather from it.
    if (segment.length !== 1) {
  • // 1-length segments only move the current generated column, there's no source information
    // to gather from it.
    if (segment.length === 1) return SOURCELESS_MAPPING;

@jridgewell
Copy link
Collaborator

I opened evanw/esbuild#4082 to resolve the bug in esbuild. Patching that and using a local build of esbuild, I can correctly generate the angular project from angular/angular-cli#29465.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants