qmhc / vite-plugin-dts

A Vite plugin for generating `.d.ts` files.
MIT License
1.31k stars 90 forks source link

The "mainEntryPointFilePath" path does not exist: ./dist/index.d.ts #275

Closed nikitamax closed 1 year ago

nikitamax commented 1 year ago

Describe the bug

I am trying to deploy project to gitlab ci-cd, but getting an error (local build without errors)

Error: Error parsing ./api-extractor.json: The "mainEntryPointFilePath" path does not exist: ./dist/index.d.ts at Function.prepare (./node_modules/@microsoft/api-extractor/src/api/ExtractorConfig.ts:1033:13) at rollupDeclarationFiles (./node_modules/vite-plugin-dts/dist/index.cjs:205:56) at Object.writeBundle (./node_modules/vite-plugin-dts/dist/index.cjs:891:13) at async Promise.all (index 0) at async PluginDriver.hookParallel (file://./node_modules/rollup/dist/es/shared/node-entry.js:25472:9) at async file://./node_modules/rollup/dist/es/shared/node-entry.js:26792:13 at async catchUnfinishedHookActions (file://./node_modules/rollup/dist/es/shared/node-entry.js:25910:16) at async Module.build (file://./node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:48074:22) at async build (./node_modules/@storybook/builder-vite/dist/index.js:159:11024) at async Promise.all (index 0)

vite.config.ts

`import { fileURLToPath, URL } from 'node:url' import { resolve } from 'path'

import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify' import dts from 'vite-plugin-dts' import { viteStaticCopy } from 'vite-plugin-static-copy'

// https://vitejs.dev/config/ export default defineConfig({ plugins: [ vue({ template: { transformAssetUrls }, }), dts({ rollupTypes: true, }), vuetify({ autoImport: true, styles: { configFile: 'src/styles/settings.scss' } }), viteStaticCopy({ targets: [ { src: 'build/scss/_variables.scss', dest: 'scss' } ] }) ], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, optimizeDeps: { include: ['vuetify'], }, // The important bit... build: { cssCodeSplit: false, lib: { // src/main.ts is where we have exported our component(s) entry: resolve(__dirname, 'src/main.ts'), formats: ['es', 'cjs'], name: 'NostroyUILibrary', fileName: format => (format === 'es' ? 'index.js' : 'index.common.js'), }, rollupOptions: { external: ['vue'], output: { globals: { vue: 'Vue', }, }, }, }, }) `

Reproduction

can't reproduce it using StackBitz

Steps to reproduce

No response

System Info

System:
    OS: macOS 14.0
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 712.72 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
    Watchman: 2023.05.15.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 117.0.5938.149
    Safari: 17.0
  npmPackages:
    @vitejs/plugin-vue: ^4.2.3 => 4.4.0 
    vite: ^4.4.5 => 4.4.11 
    vite-plugin-dts: ^3.6.0 => 3.6.0

Validations

FairyEver commented 11 months ago

how you resolved it

GoodbyeVictoria commented 11 months ago

I have this error too, how do you solve it? Do I need to create a index.d.ts file, but with what content? Could you help me with this?@qmhc

qmhc commented 11 months ago

@GoodbyeVictoria Could you provide a reproduction, I can't reproduce this issue.

tirthaguha commented 8 months ago

I have this issue, in the exact same manner. I'm using react, storybook on vite to build a component library. When I run build-storybook, it fails.

Funny, the build does not fail on local, but build always fails on CI system, running on node v18, with error

19:36:36  => Failed to build the preview
19:36:36  Error: [vite:dts] Error parsing ./api-extractor.json:
19:36:36  The "mainEntryPointFilePath" path does not exist: ./dist/index.d.ts

Please reopen this ticket.

Logs:

$ npm run build-storybook

> my-component-library@1.12.1 build-storybook
> storybook build -o ./build

@storybook/cli v7.6.16

info => Cleaning outputDir: \build
info => Loading presets
WARN The "@storybook/addon-mdx-gfm" addon is meant as a migration assistant for Storybook 7.0; and will likely be removed in a future version.
WARN It's recommended you read this document:
WARN https://storybook.js.org/docs/react/writing-docs/mdx#lack-of-github-flavored-markdown-gfm
WARN
WARN Once you've made the necessary changes, you can remove the addon from your package.json and storybook config.
info => Building manager..
info => Manager built (350 ms)
info => Building preview..
info => Copying static files: C:\WORKSPACE\test\my-component-library\node_modules\@storybook\manager\static at C:\WORKSPACE\test\my-component-library\build\sb-common-assets
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

[vite:dts] You are building a library that may not need to generate declaration files.

vite v5.1.0 building for production...

./sb-common-assets/fonts.css doesn't exist at build time, it will remain unchanged to be resolved at runtime
transforming...
node_modules/telejson/dist/index.mjs (1413:15) Use of eval in "node_modules/telejson/dist/index.mjs" is strongly discouraged as it poses security risks and may cause issues with minification.
node_modules/telejson/dist/index.mjs (1416:18) Use of eval in "node_modules/telejson/dist/index.mjs" is strongly discouraged as it poses security risks and may cause issues with minification.
āœ“ 1065 modules transformed.
rendering chunks...

[vite:dts] Start generate declaration files...
computing gzip size...
[vite:dts] Outside emitted: C:/WORKSPACE/test/my-component-library/dist/index.d.ts
[vite:dts] Start rollup declaration files...
āœ“ built in 39.91s
=> Failed to build the preview
Error: [vite:dts] Error parsing .\api-extractor.json:
The "mainEntryPointFilePath" path does not exist: .\dist\index.d.ts
    at ExtractorConfig.prepare (.\node_modules\@microsoft\api-extractor\lib\api\ExtractorConfig.js:581:19)
    at rollupDeclarationFiles (file:///C:/WORKSPACE/test/my-component-library/node_modules/vite-plugin-dts/dist/index.mjs:260:43)
    at Object.writeBundle (file:///C:/WORKSPACE/test/my-component-library/node_modules/vite-plugin-dts/dist/index.mjs:981:13)
    at async Promise.all (index 0)
    at async PluginDriver.hookParallel (file:///C:/WORKSPACE/test/my-component-library/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:18620:9)
    at async file:///C:/WORKSPACE/test/my-component-library/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:19612:13
    at async catchUnfinishedHookActions (file:///C:/WORKSPACE/test/my-component-library/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:19036:16)
    at async build (file:///C:/WORKSPACE/test/my-component-library/node_modules/vite/dist/node/chunks/dep-nGG-_oRu.js:66898:22)
    at async build (.\node_modules\@storybook\builder-vite\dist\index.js:159:11314)
    at async Promise.all (index 0)
    at async Module.build2 (.\node_modules\@storybook\builder-vite\dist\index.js:159:13633)
    at async Promise.all (index 0)
    at async buildStaticStandalone (.\node_modules\@storybook\core-server\dist\index.js:61:2295)
    at async withTelemetry (.\node_modules\@storybook\core-server\dist\index.js:65:3948)
    at async build (.\node_modules\@storybook\cli\dist\generate.js:514:1059)
    at async Command.<anonymous> (.\node_modules\@storybook\cli\dist\generate.js:530:125)

My Vite Config

import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
// import { libInjectCss } from 'vite-plugin-lib-inject-css';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    // libInjectCss(),
    dts({
      insertTypesEntry: true,
      rollupTypes: true,
    }),
  ],
  build: {
    lib: {
      entry: 'src/index.ts',
      name: 'my-component-library',
      formats: ['es', 'umd'],
      fileName: (format) => `my-component-library.${format}.js`,
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
        },
      },
    },
  },
});
tirthaguha commented 8 months ago

@qmhc would it be ok to reopen it, I can now predictably replicate it, accross win/*nix platforms.

qmhc commented 8 months ago

@tirthaguha How can I reproduce this issue in Windows system?

jurijsk commented 8 months ago

@qmhc I run into the same issue.

Got this error while trying to merge .d.ts-es into one. After fiddling with configs found a solution, you can see the setup that works here: https://github.com/jurijsk/lib-template

Problem is likely to occur if one sets vite.root to ./src and output to ../dist to have the the generated files land to ./dist instead of ./dist/src. Maybe there is a better what to do that but I don't know about it.

And then that fact that package.json/types have a says in the all this does not help ...

if you remove or change outDir or root from dts.options in my project everything will fall apart pretty quickly.

terwer commented 8 months ago
insertTypesEntry: true 

is worked for me, thanks.

hanfengv commented 2 months ago

package.json "types": "./dist/index.d.ts",

Kegulf commented 2 months ago

Hot tip for those who experienced this with a repo containing React and Storybook: Add this nifty thing to your storybook-config in .storybook/main.ts. This will remove vite-plugin-dts from your storybook build, as it strictly isn't needed there šŸ˜

import { withoutVitePlugins } from '@storybook/builder-vite';

const config = {
  ...
  async viteFinal(config) {
    config.plugins = await withoutVitePlugins(config.plugins, [
      'vite:dts',
    ]);

    return config;
  },
};

export default config;
atpradical commented 1 month ago

@Kegulf it works for me, many thanks!

Ho3einWave commented 3 weeks ago

Hot tip for those who experienced this with a repo containing React and Storybook: Add this nifty thing to your storybook-config in .storybook/main.ts. This will remove vite-plugin-dts from your storybook build, as it strictly isn't needed there šŸ˜

import { withoutVitePlugins } from '@storybook/builder-vite';

const config = {
  ...
  async viteFinal(config) {
    config.plugins = await withoutVitePlugins(config.plugins, [
      'vite:dts',
    ]);

    return config;
  },
};

export default config;

this worked for me too šŸ‘šŸ»