unplugin-dts icon indicating copy to clipboard operation
unplugin-dts copied to clipboard

3.8.0+ Cannot build while excluding vite-env.d.ts

Open danvim opened this issue 1 year ago • 0 comments

Describe the bug

I'm building a library, and when I upgraded from 3.7.3 to latest, I noticed I can no longer build as the build script complains about a global define variable cannot be found.

Previously, to omit copying over my vite-env.d.ts, I added this file to exclude:

plugins: [
    react(),
    dts({
      copyDtsFiles: true,
      exclude: ['./src/vite-env.d.ts'],
    }),
  ],

However, for version 3.8.0+, I can no longer do this. I need to remove this env file from appearing in my published package as these define variables are build time only and do not exist after building.

Is this expected behavior of this library? If so, how should I fix my problem?


build log

vite v5.2.11 building for production...
src/App.tsx:9:12 - error TS2304: Cannot find name '__APP_VERSION__'.

9       <h1>{__APP_VERSION__}</h1>
             ~~~~~~~~~~~~~~~

✓ 0 modules transformed.
x Build failed in 1.21s
error during build:
RollupError: Could not resolve entry module "src/index.ts".
    at getRollupError (/home/projects/vitejs-vite-ujc54e/node_modules/rollup/dist/es/shared/parseAst.js:551:41)
    at Module.error (/home/projects/vitejs-vite-ujc54e/node_modules/rollup/dist/es/shared/parseAst.js:547:42)
    at ModuleLoader.loadEntryModule (/home/projects/vitejs-vite-ujc54e/node_modules/rollup/dist/es/shared/node-entry.js:19152:33)

Reproduction

https://stackblitz.com/edit/vitejs-vite-ujc54e?file=src%2Fvite-env.d.ts,vite.config.ts,src%2FApp.tsx,package.json&terminal=dev

Steps to reproduce

Run npm run build

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: [redacted]
    Memory: 42.17 GB / 63.95 GB
  Binaries:
    Node: 22.1.0 - [redacted]
    Yarn: 1.22.19 - [redacted]
    npm: 10.4.0 - [redacted]
    pnpm: 9.1.1 - [redacted]
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @vitejs/plugin-react-swc: ^3.6.0 => 3.6.0
    vite: ^5.2.11 => 5.2.11
    vite-plugin-dts: ^3.9.1 => 3.9.1

Validations

danvim avatar May 15 '24 10:05 danvim