aleclarson / vite-tsconfig-paths

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

vite build.rollupOptions break proper path inference #134

Closed nik-webdevelop closed 9 months ago

nik-webdevelop commented 10 months ago

Reproduction:

in the ./demo project of the current repo:

add build.rollupOptions.input/output to vite.config.ts

for example, add additional src/utils.ts file to be bundled separetely with this config

rollupOptions: {
  input: {
    'utils': 'src/utils.ts',
    'main': 'src/main.jsx',
  },
  output: {
    format: 'es',
    dir: 'dist',
  },
}

The result is error: [vite]: Rollup failed to resolve import "@/Root" from "src/main.jsx".

aleclarson commented 10 months ago

I tried what you said, but no error in either vite dev or vite build when using Vite v5.0.10

nik-webdevelop commented 8 months ago

@aleclarson I'm really sorry for abandoning this issue like this and reviving it now, but I got some spare time and created this stackblitz with a demo folder from current repo and found out that everything works fine (as you stated).

But when i download the exact same files from stackblitz to my pc, i get errors on build. I've tried to build the same files on another PC and got the same error. I use Windows on both PCs, and i tend to think that this could be a reson for the problem.

Here is a log for build command with DEBUG=vite-tsconfig-paths

$ DEBUG=vite-tsconfig-paths pnpm run build

> demo@ build C:\MyData\projects-mine\vite-tsconfig-paths\demo > vite build

  vite-tsconfig-paths options.root   == undefined +0ms
  vite-tsconfig-paths project root   == C:/MyData/projects-mine/vite-tsconfig-paths/demo +3ms
  vite-tsconfig-paths workspace root == C:/MyData/projects-mine/vite-tsconfig-paths/demo +0ms
  vite-tsconfig-paths projects: [
  'C:\\MyData\\projects-mine\\vite-tsconfig-paths\\demo\\tsconfig.json'
] +7ms
  vite-tsconfig-paths config loaded: {
  configPath: 'C:/MyData/projects-mine/vite-tsconfig-paths/demo/tsconfig.json',
  config: {
    include: [ 'src', 'vite.config.ts' ],
    compilerOptions: {
      esModuleInterop: true,
      allowJs: true,
      checkJs: true,
      jsx: 'react-jsx',
      lib: [ 'dom', 'es2018' ],
      module: 'esnext',
      baseUrl: 'C:/MyData/projects-mine/vite-tsconfig-paths/demo',
      paths: { '@/*': [ 'src/*' ] },
      types: [ 'vite/client' ]
    }
  }
} +17ms
  vite-tsconfig-paths compiled globs: {
  includers: [
    /^\.\/src\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/vite\.config\.ts\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/vite\.config\.ts$/
  ],
  excluders: [
    /^\.\/((?:[^/]*(?:\/|$))*)node_modules\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/((?:[^/]*(?:\/|$))*)bower_components\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/((?:[^/]*(?:\/|$))*)jspm_packages\/((?:[^/]*(?:\/|$))*)$/
  ]
} +7ms
vite v5.0.10 building for production...
✓ 2 modules transformed.
[vite]: Rollup failed to resolve import "@/Root" from "C:\MyData\projects-mine\vite-tsconfig-paths\demo\src\main.jsx".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "@/Root" from "C:\MyData\projects-mine\vite-tsconfig-paths\demo\src\main.jsx".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at viteWarn (file:///C:/MyData/projects-mine/vite-tsconfig-paths/demo/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/d
ep-R0I0XnyH.js:66953:27)
    at onRollupWarning (file:///C:/MyData/projects-mine/vite-tsconfig-paths/demo/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/c
hunks/dep-R0I0XnyH.js:66981:9)
    at onwarn (file:///C:/MyData/projects-mine/vite-tsconfig-paths/demo/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep
-R0I0XnyH.js:66698:13)
    at file:///C:/MyData/projects-mine/vite-tsconfig-paths/demo/node_modules/.pnpm/rollup@4.13.0/node_modules/rollup/dist/es/shared/node-entr
y.js:18303:13
    at Object.logger [as onLog] (file:///C:/MyData/projects-mine/vite-tsconfig-paths/demo/node_modules/.pnpm/rollup@4.13.0/node_modules/rollu
p/dist/es/shared/node-entry.js:19950:9)
    at ModuleLoader.handleInvalidResolvedId (file:///C:/MyData/projects-mine/vite-tsconfig-paths/demo/node_modules/.pnpm/rollup@4.13.0/node_m
odules/rollup/dist/es/shared/node-entry.js:18893:26)
    at file:///C:/MyData/projects-mine/vite-tsconfig-paths/demo/node_modules/.pnpm/rollup@4.13.0/node_modules/rollup/dist/es/shared/node-entr
y.js:18851:26
 ELIFECYCLE  Command failed with exit code 1.