aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.24k stars 43 forks source link

I think there's a conflict with plug-in `@rollup/plugin-node-resolve` #92

Closed jjunyjjuny closed 1 year ago

jjunyjjuny commented 1 year ago

Hello, I have a problem...

I need to build some external dependencies together. (In fact, these are unbuilt pieces of code. So these have to be included in the build.) I used a '@rollup/plugin-node-resolve' as written in the rollup document.

import { resolve } from 'path'

import nodeResolve from '@rollup/plugin-node-resolve'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'
import vitePluginDts from 'vite-plugin-dts'
import tsconfigPaths from 'vite-tsconfig-paths'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({
      jsxImportSource: '@emotion/react',
    }),
    vitePluginDts({
      insertTypesEntry: true,
    }),
    tsconfigPaths({ root: './' }),
  ],
  build: {
    sourcemap: true,
    lib: {
      entry: resolve(__dirname, 'src/main.ts'),
      name: 'ProductCategory',
      fileName: 'product-category',
    },
    rollupOptions: {
      external: [
        '@emotion/react',
        '@emotion/styled',
        '@types/react',
        '@types/react-dom',
        'react',
        'react-dom',
        'typescript',
        "depenency1",
        "depenency2",
      ],
      plugins: [nodeResolve({
        resolveOnly : ["depenency1", "depenency2"]
      })],
    },
  },
})

This is the error I've encountered.

[vite:load-fallback] Could not load ~/src/@emotion/react/jsx-runtime (imported by ~/index.tsx): ENOENT: no such file or directory, open '~/src/@emotion/react/jsx-runtime'
error during build:
Error: Could not load ~/src/@emotion/react/jsx-runtime (imported by index.tsx): ENOENT: no such file or directory, open '~/src/@emotion/react/jsx-runtime'

can I help you??

jjunyjjuny commented 1 year ago

I solved this issue.

exclude 'dependency1', 'dependency2' from rollupOptions.external and remove @rollup/plugin-node-resolve