vite icon indicating copy to clipboard operation
vite copied to clipboard

preserveModulesRoot of vite configuration file is invalid in windows

Open ckvv opened this issue 2 years ago • 2 comments

Describe the bug

preserveModulesRoot of vite configuration file is invalid in windows

in windows (The src directory should not exist in the es directory)

in macos 截屏2022-01-14 下午10 53 23

Reproduction

https://github.com/ckpack/v-ui

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
    Memory: 8.44 GB / 15.83 GB
  Binaries:
    Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.11 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.22.0 - ~\AppData\Roaming\npm\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.55)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @vitejs/plugin-vue: ^2.0.1 => 2.0.1
    vite: ^2.7.10 => 2.7.12

Used Package Manager

pnpm

Logs

No response

Validations

ckvv avatar Jan 14 '22 14:01 ckvv

This seems to be an upstream issue. https://github.com/rollup/rollup/issues/4496

sapphi-red avatar Jul 10 '22 17:07 sapphi-red

+1, i have same problem。

after debugging, I found that it is caused by the following code

at 'rollup/src/utils/options/normalizeOutputOptions.ts'

...
preserveModulesRoot: getPreserveModulesRoot(config),
....

const getPreserveModulesRoot = (
	config: OutputOptions
): NormalizedOutputOptions['preserveModulesRoot'] => {
	const { preserveModulesRoot } = config;
	if (preserveModulesRoot === null || preserveModulesRoot === undefined) {
		return undefined;
	}
	return resolve(preserveModulesRoot);
};

but, at ''src/chunk.ts" 中

const currentPath = `${currentDir}/${fileName}`;
const { preserveModulesRoot } = options;
if (preserveModulesRoot && currentPath.startsWith(preserveModulesRoot)) {
	path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, '');
} else {
	path = relative(preserveModulesRelativeDir, currentPath);
}

currentPath not resolve, but preserveModulesRoot had resolve, so in windows platform,currentPath.startsWith(preserveModulesRoot) always be false。

cleverpp avatar Jul 28 '22 09:07 cleverpp

This is due to vite normalized the slashs while rollup leaves it platform-dependent. See the complete comment here: https://github.com/rollup/rollup/pull/4591#issuecomment-1201952230

Tanimodori avatar Aug 02 '22 03:08 Tanimodori

This issue is fixed in rollup 2.77.3

Tanimodori avatar Aug 11 '22 07:08 Tanimodori