---
source_url: https://itmustbecode.com/pcf-control-compile-error-cannot-find-module-ajv-dist-compile-codegen/
title: PCF Control compile error : Cannot find module 'ajv/dist/compile/codegen'
date: 2023-01-03T18:09:56+00:00
categories:
  - blog
tags:
  - dataverse
  - pac-cli
  - pcf
word_count: 257
reading_time_minutes: 2
type: posts
---

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**)

{{< figure src="./image.png" alt="" caption="" >}}

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 :

{{< figure src="./image-2.png" alt="" caption="" >}}

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

{{< figure src="./image-3.png" alt="" caption="" >}}

I came across a similar issue ( _yet unrelated to PCF control development_) on [Stack Overflow](https://stackoverflow.com/questions/70020046/quasar-error-cannot-find-module-ajv-dist-compile-codegen). 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
```

{{< figure src="./image-6.png" alt="" caption="" >}}

As you can see the missing module can now be found in the **node\_modules** directory.

{{< figure src="./image-7.png" alt="" caption="" >}}

And the project compiles flawlessly.

{{< figure src="./image-8.png" alt="" caption="" >}}

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.

