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 compilation error due to @ alias when attempting to use library #1

Open
chamby opened this issue Jul 30, 2024 · 1 comment
Open

Comments

@chamby
Copy link

chamby commented Jul 30, 2024

✘ [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 vitejs/vite#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
Copy link
Author

chamby commented Jul 30, 2024

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"),
  },
},

@chamby chamby closed this as completed Jul 30, 2024
@chamby chamby reopened this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant