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

'rootDir' is expected to contain all source files. Error existed when generating dts file in monorepo project #210

Closed
3 tasks done
gkn1234 opened this issue May 15, 2023 · 3 comments

Comments

@gkn1234
Copy link

gkn1234 commented May 15, 2023

Describe the bug

A TS error existed when generating dts file in monorepo project.

[vite:dts] Start generate declaration files...
src/index.ts:1:22 - error TS6059: File '/home/projects/vitejs-vite-ceq4fy/packages/b/src/index.ts' is not under 'rootDir' '/home/projects/vitejs-vite-ceq4fy/packages/a'. 'rootDir' is expected to contain all source files.

1 import { b, B } from '@mine/b';
                       ~~~~~~~~~

✓ built in 1.94s
[vite:dts] Declaration files built in 1809ms.

My vite.config.ts file in package @mine/a

import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';

export default defineConfig(() => ({
  plugins: [
    dts({
      entryRoot: 'src',
      tsConfigFilePath: '../tsconfig.json',
      skipDiagnostics: false,
      compilerOptions: {
        // rootDir: '..',
      },
    }),
  ],
  build: {
    lib: {
      entry: './src/index.ts',
      name: 'a',
      fileName: 'a',
    },
    minify: false,
    emptyOutDir: true,
    sourcemap: false,
    rollupOptions: {
      external: [/@mine\/.*/],
      output: {
        globals: {},
      },
    },
  },
}));

The error doesn't exist when rootDir is .., but no dts file has been created.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ceq4fy?file=packages/a/package.json

Steps to reproduce

Run pnpm --filter @mine/a run build

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Memory: 12.83 GB / 31.78 GB
  Binaries:
    Node: 18.16.0 - D:\devApp\nodejs\node.EXE
    Yarn: 1.22.18 - D:\devApp\nodejs\yarn.CMD
    npm: 9.5.1 - D:\devApp\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (113.0.1774.42)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    vite: ^4.3.5 => 4.3.5
    vite-plugin-dts: ^2.3.0 => 2.3.0

Validations

@jmuzsik
Copy link

jmuzsik commented May 16, 2023

Have the same error. So, migrating from tsup to vite because of build error's (specifically this error in aws amplify: aws-amplify/amplify-js#9639). I am using turborepo

So, for me, asfaik it is because of my importing within the monorepo

folder structure:

rootStuff (package.json, etc.)
packages
  somePackage (with package.json, vite config, etc.) - this package is to be a module published to npm
  someOtherPackage (with package.json, vite config, etc.)

Basically, i in, say, somePackage/src/**/someFile i do import something from '../../../someOtherPackage/etc' and the error happens.

It builds fine, just fails at the typings, which was not problematic with tsup.

trying to figure out a workaround now, thought i'd just share this

@jmuzsik
Copy link

jmuzsik commented May 17, 2023

as a temporary workaround i am doing this:

   "build": "vite build && npm run types",
   "types": "tsup src/index.ts --dts-only",

so build first, then tsup to create types, all getting set into a dist folder

@qmhc
Copy link
Owner

qmhc commented Jun 30, 2023

Fixed in 3.0.0.

@qmhc qmhc closed this as completed Jun 30, 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

No branches or pull requests

3 participants