-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Describe the bug
For reference, please see this repo. In the repo, I have a sample library that I'm building with vite. When it gets built, it includes 3 JS files:
- classes.js
- index.js
- injectionKeys.js
The respective type files are also included, but they're not important. When I build this on Windows 10 using npm 8.15.0 and node 16.17.0, I get a strange result. In index.js
on line 2, where it's supposed to import injectionKeys.js
, it actually just adds the code const AppConfigKey = Symbol("AppConfig");
. This is obviously problematic because the symbols are not unique if I'm then importing injectionKeys.js
outside of the lib. When I build this on Ubuntu, I do not get this issue.
Furthermore, if I build this with rollup (with what I believe is almost the same configuration) using npm run build:rollup
, I don't get this issue on Windows.
Do note that I'm using vite@2.9.15 because of the known issue with lib builds in v3.
Reproduction
https://github.com/incutonez/windows-linux-vite
System Info
- Windows 10 Home, 21H2
- node 16.17.0
- npm 8.15.0
Used Package Manager
npm
Logs
index.js built with vite on Win10
import { defineComponent, inject, openBlock, createElementBlock, toDisplayString } from "vue";
// THIS LINE RIGHT HERE IS THE PROBLEM
const AppConfigKey = Symbol("AppConfig");
var _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
const _sfc_main$1 = defineComponent({
name: "BarCmp",
setup() {
const appConfig = inject(AppConfigKey);
console.log("in BarCmp", appConfig);
return {
appConfig
};
}
});
function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
var _a;
return openBlock(), createElementBlock("article", null, " Bar: The Base URL is " + toDisplayString((_a = _ctx.appConfig) == null ? void 0 : _a.BaseUrl), 1);
}
var BarCmp = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
const _sfc_main = defineComponent({
name: "FooCmp",
setup() {
const appConfig = inject(AppConfigKey);
console.log("in FooCmp", appConfig);
return {
appConfig
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
var _a;
return openBlock(), createElementBlock("article", null, " Foo: The Base URL is " + toDisplayString((_a = _ctx.appConfig) == null ? void 0 : _a.BaseUrl), 1);
}
var FooCmp = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export { BarCmp, FooCmp };
index.js built with rollup on Win10
import { defineComponent, inject, openBlock, createElementBlock, toDisplayString } from 'vue';
// THIS LINE RIGHT HERE IS CORRECT
import { AppConfigKey } from './injectionKeys.js';
var _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
const _sfc_main$1 = defineComponent({
name: "BarCmp",
setup() {
const appConfig = inject(AppConfigKey);
console.log("in BarCmp", appConfig);
return {
appConfig
};
}
});
function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("article", null, " Bar: The Base URL is " + toDisplayString(_ctx.appConfig?.BaseUrl), 1);
}
var BarCmp = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__file", "C:\\Users\\incut\\workspace\\windows-linux-vite\\src\\components\\BarCmp.vue"]]);
const _sfc_main = defineComponent({
name: "FooCmp",
setup() {
const appConfig = inject(AppConfigKey);
console.log("in FooCmp", appConfig);
return {
appConfig
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("article", null, " Foo: The Base URL is " + toDisplayString(_ctx.appConfig?.BaseUrl), 1);
}
var FooCmp = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "C:\\Users\\incut\\workspace\\windows-linux-vite\\src\\components\\FooCmp.vue"]]);
export { BarCmp, FooCmp };
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- 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 vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.