Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite builds the same code, there will be product inconsistencies #14466

Closed
7 tasks done
gzzhengbingyi opened this issue Sep 25, 2023 · 1 comment
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@gzzhengbingyi
Copy link

Describe the bug

The code is as follows:

import 'dayjs/locale/zh-cn';

import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';

dayjs.locale('zh-cn');
dayjs.Ls['zh-cn'].weekStart = 1;
dayjs.extend(relativeTime);

The products generated are in two forms:
image
and
image

The difference in build products leads to a domino-like effect that makes most file hashes change.

After looking at the source code, I found that the main thing is that vite builds with the worker execution @rollup/plugin-commonjs plugin turned on, and the code is written in such a way that dayjs and import 'dayjs/locale/zh-cn'; seem to have no dependency on each other, resulting in them being executed in the main process and the worker process respectively The order of execution is uncertain, sometimes dayjs is built first, sometimes zh-cn.js is executed first, which leads to different final packaged products.

Reproduction

not have

Steps to reproduce

Same as the bug description above

System Info

System:
    OS: macOS 13.4.1
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 443.02 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 9.6.7 - /usr/local/bin/npm
    pnpm: 8.6.10 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 117.0.5938.92
    Chrome Canary: 119.0.6028.0
    Safari: 16.5.2
  npmPackages:
    @vitejs/plugin-vue: ^4.2.3 => 4.2.3 
    @vitejs/plugin-vue-jsx: ^3.0.1 => 3.0.1 
    vite: ^4.4.8 => 4.4.8

Used Package Manager

npm

Logs

// packages/commonjs/src/resolve-require-sources.js
const setInitialParentType = (id, initialCommonJSType) => {
// Fully analyzed modules may never change type
if (fullyAnalyzedModules[id]) {
return;
}
knownCjsModuleTypes[id] = initialCommonJSType;
if (id.indexOf('dayjs.min.js') !== -1) {
console.log('requiredIds: ', requiredIds); // Logs manually added to the source code
}
if (
detectCyclesAndConditional &&
knownCjsModuleTypes[id] === true &&
requiredIds[id] &&
!unconditionallyRequiredIds[id]
) {
knownCjsModuleTypes[id] = IS_WRAPPED_COMMONJS;
}
};

The contents of the log are of the following two kinds:
requiredIds: [Object: null prototype] {}

and

requiredIds: [Object: null prototype] {
'/Users/userName/projectName/node_modules/dayjs/dayjs.min.js': true
}

Validations

@sapphi-red
Copy link
Member

Duplicate of #13672

@sapphi-red sapphi-red marked this as a duplicate of #13672 Nov 7, 2023
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Nov 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants