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

Windows Lib Build Not Correct #9939

Closed
7 tasks done
incutonez opened this issue Sep 1, 2022 · 3 comments
Closed
7 tasks done

Windows Lib Build Not Correct #9939

incutonez opened this issue Sep 1, 2022 · 3 comments
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) windows only

Comments

@incutonez
Copy link

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

@sapphi-red
Copy link
Member

Changing build.rollupOptions.input to

      input: {
        index: path.resolve(__dirname, 'src/components/index.ts'),
        injectionKeys:  path.resolve(__dirname, 'src/InjectionKeys.ts'),
        classes:  path.resolve(__dirname, 'src/classes/AppConfig.ts')
      },

seems to work. Maybe it's a similar to rollup/rollup#4591.

@sapphi-red sapphi-red added windows only p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Sep 1, 2022
@incutonez
Copy link
Author

That is very interesting... it does indeed fix the issue. Thanks for that workaround!

@sapphi-red
Copy link
Member

Closing as the reproduction was deleted.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) windows only
Projects
None yet
Development

No branches or pull requests

2 participants