Skip to content

preserveModulesRoot of vite configuration file is invalid in windows #6509

Closed

Description

@ckvv

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

Activity

  1. sapphi-red commented on Jul 10, 2022

    @sapphi-red
    Member

    This seems to be an upstream issue.
    rollup/rollup#4496

  2. added
    bug: upstream
    and removed on Jul 10, 2022
  3. cleverpp commented on Jul 28, 2022

    @cleverpp

    +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。

  4. Tanimodori commented on Aug 2, 2022

    @Tanimodori

    This is due to vite normalized the slashs while rollup leaves it platform-dependent. See the complete comment here: rollup/rollup#4591 (comment)

  5. Tanimodori commented on Aug 11, 2022

    @Tanimodori

    This issue is fixed in rollup 2.77.3

  6. locked and limited conversation to collaborators on Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamwindows only

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions