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

Source map files not generated when exported on entry #259

Closed
3 tasks done
2wheeh opened this issue Aug 7, 2023 · 2 comments · Fixed by #260
Closed
3 tasks done

Source map files not generated when exported on entry #259

2wheeh opened this issue Aug 7, 2023 · 2 comments · Fixed by #260

Comments

@2wheeh
Copy link
Contributor

2wheeh commented Aug 7, 2023

Describe the bug

Source map files are not being generated in the following scenarios:

  1. When the source file is the entry point.
  2. When a file is exported from the entry point.

It can be reproduced with below code structure

// src/index.ts <- entry
export * from './foo'

// src/foo/index.ts
export { bar } from './bar'

// src/foo/bar.ts
export const bar = 'bar'

After building, I expected source map files generated for the .d.ts files as shown below

dist
  |_ foo
  |  |_index.d.ts
  |  |_index.d.ts.map
  |  |_bar.d.ts
  |  |_bar.d.ts.map
  |_index.d.ts
  |_index.d.ts.map
  |_ ...

but none of these 3 .d.ts files doesn't generate their corresponding source map files.

Here is the config that I used to reproduce, which is the one in reproduction link.

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import dts from 'vite-plugin-dts';
import { resolve } from 'node:path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    dts({
      include: ['src'],
      insertTypesEntry: true,
      outDir: ['dist'],
      tsconfigPath: resolve(__dirname, 'tsconfig.json'),
      compilerOptions: {
        declaration: true,
        declarationMap: true,
      },
    }),
  ],
  build: {
    sourcemap: true,
    lib: {
      entry: resolve('src', 'index.ts'),
      name: 'my-lib',
      formats: ['es', 'cjs'],
      fileName: (format) => `index.${format === 'cjs' ? 'cjs' : 'es.js'}`,
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
        },
      },
    },
  },
});

Reproduction

https://stackblitz.com/edit/vitejs-vite-z9j9ux?file=package.json

Steps to reproduce

  1. Run vite build on terminal
  2. Check dist directory

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.6.10 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.0.4 => 4.0.4 
    vite: ^4.4.8 => 4.4.8 
    vite-plugin-dts: ^3.5.1 => 3.5.1

Validations

@2wheeh
Copy link
Contributor Author

2wheeh commented Aug 7, 2023

I checked that it works till @3.3.1 and since @3.4.0 it hasn't generated declarationMap files.
it works on @3.3.1 => https://stackblitz.com/edit/vitejs-vite-qnchol?file=package.json

@olegKusov
Copy link

olegKusov commented Aug 8, 2023

Same issue. it do not work even with 3.3.1 version

@qmhc qmhc closed this as completed in #260 Aug 12, 2023
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.

2 participants