I was working on a new PCF control project and I encountered an unexpected error when attempting to build the project, even though no custom code had been added yet. (Cannot find module ajv/dist/compile/codegen)
For reference, I’m using the latest version (at the time of writing) of the Microsoft Power Platform CLI (1.21.4+g4869036) and here are the steps to reproduce :
- Execute the init method of the pac cli. This will scaffold a new PCF control projects with all the basic dependencies.
- Execute npm install to download the dependencies
- Try to build the project : npm run build
- ❌Fails with error : Cannot find module “ajv/dist/compile/codegen”
pac pcf init -ns <Namespace> -n <ProjectName> -t field
npm install
npm run build
The error message is quite straitforward and points toward a node module that cannot be found : ajv/dist/compile/codegen . Upon checking the node_modules directory, even if the ajv module seems present, the compile/codegen part is nowhere to be found.
I came across a similar issue (yet unrelated to PCF control development) on Stack Overflow. Based on the accepted answer, I just added a reference to the ajv package in the dev dependencies of the PCF project.
npm install --save-dev ajv
As you can see the missing module can now be found in the node_modules directory.
And the project compiles flawlessly.
Hopefully this issue will be resolved quickly in future updates to the Microsoft Power Platform CLI. In the meantime, it is good to know that there is a workaround for it.
Hope this helps.
David,
I appreciate you making this post. I was having the same issue with a PCF component today and was able to easily fix it thanks to you.
It’s good to hear that my article was able to assist you, thanks for the feedback.
Thanks for this great article. It saved my day! I was struggling to get the PCF control to work and thanks to this I was able to get it to work!
I’m really glad to hear that 😉
Thank you, David! You saved my day 🙂
Thanks for this post, just what I needed.
Thanks for the post. Solved my issue.