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

Getting "Cannot find module 'ajv/dist/core'" when trying to build a library #388

Open
3 tasks done
elShailee opened this issue Oct 10, 2024 · 4 comments
Open
3 tasks done

Comments

@elShailee
Copy link

elShailee commented Oct 10, 2024

Describe the bug

I'm trying to build my first ts/react library, following this article:
https://dev.to/receter/how-to-create-a-react-component-library-using-vites-library-mode-4lma

when I got to section "Building the types", which suggests installing this library, I get this error when attempting build:
{029D59B3-97BF-477E-B590-9DA9C8DC086B}

So far I've tried anything I could find online + upgrading my node js version, but nothing has worked.

I've tried to replicate it via StackBlitz for you, but of course it works there -_-
If you like to see the code I have now, here it is, to the letter:
https://stackblitz.com/edit/vitejs-vite-5ph2e3

Thanks in advance!

Reproduction

https://stackblitz.com/edit/vitejs-vite-5ph2e3

Steps to reproduce

I failed to reproduce via StackBlitz, but the code is there exactly as it is on my machine.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 Intel(R) Xeon(R) W-11855M CPU @ 3.20GHz
    Memory: 13.11 GB / 31.21 GB
  Binaries:
    Node: 20.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @vitejs/plugin-react: ^4.3.2 => 4.3.2 
    vite: ^5.4.8 => 5.4.8 
    vite-plugin-dts: ^4.2.3 => 4.2.3

Validations

@elShailee
Copy link
Author

of course I find this solution 15 minutes later:
https://stackoverflow.com/questions/70020046/quasar-error-cannot-find-module-ajv-dist-compile-codegen
so I seem to be doing okay now.

still looks like something that can be improved though.

@NicolasOmar
Copy link

I came here to look for the same problem and found a solution immediately.
Thank you for leaving it, @elShailee.

@receter
Copy link

receter commented Nov 20, 2024

I was able to reproduce this with my repo https://github.com/receter/my-component-library if I upgrade to vite-plugin-dts@4 and install dependencies with --legacy-peer-deps

This can also happen if you accidentally have added --legacy-peer-deps to your global npm config (like I did a while ago)

When using --legacy-peer-deps peer deps are not installed automatically

Summary
If you use vite-plugin-dts@4 and have to use --legacy-peer-deps for whatever reason, you need to install ajv manually.

@NicolasOmar
Copy link

What @receter said worked for me. I removed a .npmrc file from my repo's root, made a clean install, and it worked without trouble.
It is an excellent alternative situation and solution if you need it.

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

3 participants