vite
vite copied to clipboard
preserveModulesRoot of vite configuration file is invalid in windows
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
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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
This seems to be an upstream issue. https://github.com/rollup/rollup/issues/4496
+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。
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
This issue is fixed in rollup 2.77.3