Skip to content

PCF Control compile error : Cannot find module ‘ajv/dist/compile/codegen’

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 :

  1. Execute the init method of the pac cli. This will scaffold a new PCF control projects with all the basic dependencies.
  2. Execute npm install to download the dependencies
  3. Try to build the project : npm run build
  4. ❌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.

Published inBlog

6 Comments

  1. 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.

    • David Rivard

      It’s good to hear that my article was able to assist you, thanks for the feedback.

  2. Johan van der Schelling

    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!

    • David Rivard

      I’m really glad to hear that 😉

  3. Igor Belczewski

    Thank you, David! You saved my day 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *