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

[@rollup/plugin-typescript]: sourceMap file generated by rollup references compiled sources rather than original sources #1832

Open
bcoe opened this issue Jan 6, 2025 · 1 comment

Comments

@bcoe
Copy link

bcoe commented Jan 6, 2025

Expected Behavior

The content of build/index.cjs.map should reference the original .ts files that rollup has built build/index.cjs from, i.e.,

  • sourcesContent contains the original .ts source files.
  • the ranges in mappings reference character positions in the original .ts files.

Actual Behavior

  • sourcesContent contains the transpiled JavaScript code, with TypeScript annotations removed.
  • mappings appears to also reference the transpiled positions in code, rather than the original positions.

Additional Information

@cristian-eriomenco
Copy link

cristian-eriomenco commented Jan 8, 2025

I have tried to setup a gazillion times sourcemapping with rollup + ts but never had luck. There's always a bug somewhere. It would help a lot if the author provided a full working example that is maintained which is a realistic use case with tree shaking working. terser, commonjs and preserveModules: true, and paths in tsconfig defined.

Our team can't debug code efficiently, I've reached a point where I feel like searching for an alternative due to lack of simple working demo. Lots of repeated github issues on this, SO questions from 2020 yet no solution or help.

A simple integration example aka:

const core = {
  input: ['./src/index.ts'],
  output: ['esm', 'cjs'].map((name) => ({
    dir: `dist/${name}`,
    format: name,
    preserveModules: true,
    preserveModulesRoot: 'src',
    sourcemap: true,
    exports: 'named',
  })),
  plugins: [
    peerDepsExternal(),
    resolve(),
    commonjs({ include: ['node_modules/**'] }),
    json(),
    typescript({
      tsconfig: './tsconfig.rollup.json',
      sourceMap: true,
      inlineSources: true,
    }),
    terser(),
  ],
};

That guarantees:

  1. Typescript intellisense works.
  2. Source map works
  3. Tree shaking works
  4. Path aliases work
  5. preserveModules: true

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

No branches or pull requests

2 participants