Ajv: missing file

Created on 29 Nov 2018  ·  23Comments  ·  Source: ajv-validator/ajv

In the last v6.6.0 release, there is a missing file:

Error: Cannot find module 'ajv/lib/compile/equal'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/home/travis/build/fastify/fastify/node_modules/table/dist/validateConfig.js:2:13)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Module.replacementCompile (/home/travis/build/fastify/fastify/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Object.<anonymous> (/home/travis/build/fastify/fastify/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/home/travis/build/fastify/fastify/node_modules/table/src/makeConfig.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:722:30)

See https://travis-ci.org/fastify/fastify/jobs/461147572
and https://github.com/fastify/fastify/issues/1281.

Most helpful comment

Other solution is to add a manual resolution in the package.json:

  "resolutions": {
    "ajv": "6.5.5"
  },

then you can use both yarn or npm

All 23 comments

I have this issue when I do yarn install. When I do npm install I do not have this issue

Other solution is to add a manual resolution in the package.json:

  "resolutions": {
    "ajv": "6.5.5"
  },

then you can use both yarn or npm

So it appears that several libraries depended on an internal file that was not public (I think) and that became one-line wrapper around fast-deep-equal long time ago... Who would have thought :)

@mcollina @gajus could you please replace require(“ajv/lib/compile/equal”) with require(“fast-deep-equal”)? I won’t be able to revert for several hours I am afraid.

Even if I do revert, it’s worth replacing anyway.

@epoberezkin just revert it temporary

Temporary workaround for this is to add this to your package.json:

  "resolutions": {
    "ajv": "6.5.4"
  }

Is this resolutions workaround for yarn only? Not npm?

@ybiquitous it works for both

Is there resolutions description in NPM docs?
https://docs.npmjs.com/files/package.json

I try resolutions via npm command:

Dockerfile:

FROM node:10

RUN apt-get -y update && apt-get -y install jq

RUN mkdir foo && \
    cd foo && \
    npm init -y && \
    cat package.json | jq '. + {resolutions: {ajv: "6.5.4"}}' > package.json.new && \
    mv package.json package.json.old && \
    mv package.json.new package.json && \
    cat package.json | jq . && \
    npm i stylelint && \
    echo '{}' > .stylelintrc && \
    echo 'a{}' > a.css

RUN npx stylelint a.css

Run docker build . command on terminal:

$ docker build .
...
{
  "name": "foo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "resolutions": {
    "ajv": "6.5.4"
  }
}
npm WARN deprecated [email protected]: CircularJSON is in maintenance only, flatted is its successor.
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ [email protected]
added 369 packages from 202 contributors and audited 2446 packages in 12.956s
found 0 vulnerabilities

Removing intermediate container 4f7a327976d5
 ---> c5752e2203f1
Step 4/4 : RUN npx stylelint a.css
 ---> Running in 73ad541c7eff
npx: installed 369 in 5.828s
Cannot find module 'ajv/lib/compile/equal'
The command '/bin/sh -c npx stylelint a.css' returned a non-zero code: 1

The result fails. Is npm support resolutions really? Or my verification is bad something?

Temporary workaround for this is to add this to your package.json:
it works for yarn and npm

  "resolutions": {
    "ajv": "@6.5.4"
  }

resolutions not support by npm.

For npm you need to "ajv": "6.5.4" dependencies in package.json

My final Dockerfile.

For resolutions approach yarn works, but npm does NOT work. 😢

FROM node:10

RUN apt-get -y update && apt-get -y install jq

RUN curl -o- -L https://yarnpkg.com/install.sh | bash

RUN mkdir foo
WORKDIR foo

RUN npm init -y && \
    cat package.json | jq '. + {resolutions: {ajv: "6.5.4"}}' > package.json.new && \
    mv package.json package.json.old && \
    mv package.json.new package.json && \
    cat package.json | jq . && \
    npm install stylelint && \
    # yarn add stylelint && \    #<=== It works!
    npm ls ajv && \
    echo '{"rules":{}}' > .stylelintrc && \
    echo 'a{}' > a.css

RUN ./node_modules/.bin/stylelint a.css

npm case:

image

Temporary workaround summary

Add a below field to your package.json.

Yarn

{
  "resolutions": {
    "ajv": "6.5.5"
  }
}

NPM

{
  "dependencies": {
    "ajv": "6.5.5"
  }
}

I will revert, it’ll go out in the next major version. Give me an hour - just landed :)

Good old release and run routine...

Yeah - I was looking at the problem in table (gajus/table#83), and it appears that this update _needs_ to be a major version, as it otherwise could break validators generated from previous versions of the library (using ajv-cli, in the case of table).

@epoberezkin Publish v6.6.1 please.

Yes, that’s why I probably kept it at the time... it’s published

So “equal.js” is public as it turned out...
https://github.com/epoberezkin/ajv/issues/889#issuecomment-442784790

Sorry

Everyday we break semver :laughing:
J/K

@epoberezkin Thank you so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JonathanWilbur picture JonathanWilbur  ·  3Comments

dci-aloughran picture dci-aloughran  ·  5Comments

fabiospampinato picture fabiospampinato  ·  3Comments

sundriver picture sundriver  ·  3Comments

radio-miskovice picture radio-miskovice  ·  6Comments