Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Version 2.30 -> TypeError: Cannot read properties of undefined (reading 'map') #193

Closed
JarekToro opened this issue Sep 4, 2024 · 5 comments

Comments

@JarekToro
Copy link

This seems familiar but not the same as these issues. The issues below mention how @jridgewell/trace-mapping had a bug that caused this. And you need a newer version. I have the newest version and am still having the problem.

#163
#158

I have these versions
"name": "@ampproject/remapping",
"version": "2.3.0",

"name": "@jridgewell/trace-mapping",
"version": "0.3.25",

This is the thrown error

TypeError: Cannot read properties of undefined (reading 'map')
❯ originalPositionFor node_modules/@ampproject/remapping/dist/remapping.mjs:78:17
❯ originalPositionFor node_modules/@ampproject/remapping/dist/remapping.mjs:89:12
❯ traceMappings node_modules/@ampproject/remapping/dist/remapping.mjs:53:26
❯ remapping node_modules/@ampproject/remapping/dist/remapping.mjs:197:26
❯ excludeGeneratedCode node_modules/@vitest/coverage-v8/dist/provider.js:2632:23
❯ V8CoverageProvider.getSources node_modules/@vitest/coverage-v8/dist/provider.js:2567:20
❯ node_modules/@vitest/coverage-v8/dist/provider.js:2502:38
❯ V8CoverageProvider.getUntestedFiles node_modules/@vitest/coverage-v8/dist/provider.js:2500:25
❯ V8CoverageProvider.generateCoverage node_modules/@vitest/coverage-v8/dist/provider.js:2389:32
❯ node_modules/vitest/dist/chunks/cli-api.OKfd3qJ0.js:14947:24
❯ Vitest.runFiles node_modules/vitest/dist/chunks/cli-api.OKfd3qJ0.js:14955:12
❯ Vitest.start node_modules/vitest/dist/chunks/cli-api.OKfd3qJ0.js:14804:7
❯ startVitest node_modules/vitest/dist/chunks/cli-api.OKfd3qJ0.js:15893:7
❯ start node_modules/vitest/dist/chunks/cac.DGgmCKmU.js:1499:17
❯ CAC.run node_modules/vitest/dist/chunks/cac.DGgmCKmU.js:1479:3
@JarekToro
Copy link
Author

in remapping.mjs I added a null check on source. It seems to solve the issues im running into.

function originalPositionFor(source, line, column, name) {
   + if (!source){
   +    return null
   +  }
    if (!source.map) {
        return SegmentObject(source.source, line, column, name, source.content, source.ignore);
    }
    const segment = traceSegment(source.map, line, column);
    // If we couldn't find a segment, then this doesn't exist in the sourcemap.
    if (segment == null)
        return null;
    // 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;
    return originalPositionFor(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
}

@yumauri
Copy link

yumauri commented Sep 8, 2024

Encountered the same issue with vitest.
It is strange though, that issue happens only in workspace environment in my case.
Adding source null check solves issue as well.

@jnhooper
Copy link

jnhooper commented Nov 1, 2024

in case anyone else ends up here, this was fixed for me by upgrading vitest from 1 to 2.1.4

@jridgewell
Copy link
Collaborator

Just looking into this. Seems like vitest was producing an source map: vitest-dev/vitest#6526. Looks like this is fixed with vitejs/vite#18204

@nwalters512
Copy link

nwalters512 commented Jan 9, 2025

I'm still experiencing this on Vite 5.4.10, which should include the changes linked above (per https://github.com/vitejs/vite/blob/v5.4.11/packages/vite/CHANGELOG.md, they were released in 5.4.9). This is reproducible here: getsentry/sentry-javascript#14968. Should I report this upstream to vite or vitest? Or per vitest-dev/vitest#6526 (comment), do I need to upgrade to vite 6 / vitest 2?

Edit: looks like upgrading to vitest 2 did the trick!

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

No branches or pull requests

5 participants