Skip to content

Windows Lib Build Not Correct #9939

@incutonez

Description

@incutonez

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)windows only

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions