ohmygodvt95 / vue3-pikaday

Vue3 wrapper component for Pikaday
MIT License
1 stars 0 forks source link

Vite compilation error due to @ alias when attempting to use library #1

Open chamby opened 1 month ago

chamby commented 1 month ago
✘ [ERROR] Could not read from file: /MY_PROJECT_@_ALIAS_ROOT/dist/VPikaday.esm

    node_modules/@ohmygodvt95/vue3-pikaday/index.js:1:21:
      1 │ import VPikaday from "@/dist/VPikaday.esm";
        ╵                      ~~~~~~~~~~~~~~~~~~~~~

I have defined the @ alias for my project. Vite is picking up the import VPikaday from "@/dist/VPikaday.esm"; and interpreting your @ alias as my alias. I wasn't aware that Vite does this for imports from node_modules. I tried to find best practice for whether or not to use aliases in the index.js entry point file but could not find much. Here is an issue report https://github.com/vitejs/vite/issues/2290 in the Vite repo that didn't offer a workaround. Could you change the import to a simple relative path instead? The alias shouldn't be necessary in the entry point file.

I have not created an NPM package myself so let me know I am off base.

chamby commented 1 month ago

I worked around this by aliasing your precise import in my project. This feels brittle to me, but at least I have a workaround.

resolve: {
  alias: {
    "@/dist/VPikaday.esm": "./dist/VPikaday.esm.js",
    "@": path.resolve(__dirname, "resources/assets/js"),
  },
},