webpack: webpack broken by ajv@6.9.0, "custom keyword definition is invalid: data.errors should be boolean"

Bug report

What is the current behavior? A fresh install of webpack will fail to run with the error “custom keyword definition is invalid: data.errors should be boolean” due to the latest version of ajv. See issue here https://github.com/epoberezkin/ajv/issues/941 referencing many other broken projects.

If the current behavior is a bug, please provide the steps to reproduce. Install webpack and attempt to use it.

What is the expected behavior? I expect webpack not to fail due to unreliable, auto-updating dependencies.

Other relevant information: webpack version: 4.28.4 Node.js version: 10.15.1 Operating System: Windows 10 Additional tools:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 163
  • Comments: 75 (5 by maintainers)

Commits related to this issue

Most upvoted comments

If you use yarn

add below to package.json

  "resolutions": {
    "ajv": "6.8.1"
  }

then run yarn install

if you use npm

npm uninstall ajv
npm install ajv@6.8.1

Or add this to your package.json:

  "resolutions": {
    "ajv": "6.8.1"
  }

Then yarn install.

For npm users:

rm -rf node_modules
npx npm-force-resolutions
npm install

Quick fix, in node_modules\ajv\lib\keyword.js I commented out if (!validateDefinition(definition)) throw new Error('custom keyword definition is invalid: ’ + this.errorsText(validateDefinition.errors)); and it works, still waiting for fix

Worked for me, npm uninstall ajv npm install ajv@6.8.1

same here

Same

To fix this error, just change: Line 14: errors: 'full', to: Line 14: errors: true in file node_modules\ajv-errors\index.js

Would this failure have been prevented if Webpack pinned all versions in package.json, and only updated them when all tests pass?

I see this comment has a few thumbs downs already, but no discussion about why it’s a bad idea. I use this strategy in several open-source libraries with lots of projects depending on them. If it’s a bad idea, I’d like to know why. Please educate me.

Dependency updates can be maintained automatically by something like the renovate bot, or pseudo-manually using updtr.

Note that resolutions is a yarn feature and not an npm feature. From the linked ajv issue:

just add

  "resolutions": {
    "ajv": "6.8.1"
  }

to your package.json

if you use yarn: run yarn install

if you use npm: https://github.com/rogeriochaves/npm-force-resolutions TL;DR

rm -rf node_modules
npx npm-force-resolutions
npm install

Hey everyone thanks for all the quick feedback. We will reach out to AJV and see if we can tighten up the communication channels for their API and will consider pinning this dep for the future. I will lock the thread once I get off mobile (bad winter storm here right now and losing power intermittently 😂🥶) since there are quite a few workarounds posted!

npm uninstall ajv npm install ajv@6.8.1

This worked for me! Thanks!

Or add this to your package.json:

  "resolutions": {
    "ajv": "6.8.1"
  }

Seems so simple I would love it to work, but getting same error, anything else I should look at?

Have you reinstalled your packages with npm install? ;p

I did, didn’t seem to fix it for me either.

Or add this to your package.json:

  "resolutions": {
    "ajv": "6.8.1"
  }

Seems so simple I would love it to work, but getting same error, anything else I should look at?

Worked for me, npm uninstall ajv npm install ajv@6.8.1

Worked like a charm!

Ran into this when updating the dev deps for Aurelia, it breaks just about everything. I have a PR open here: https://github.com/epoberezkin/ajv/pull/943 (FYI: I am NOT the maintainer of the project, just trying to help)

Another option is to lockdown to 4.28.x the webpack itself

"webpack": "~4.28.0"

updating package-lock.json definitions worked on my end, there were many referencing 6.9.0 and I clobbered them all back to 6.8.1 as below.

"ajv": {
	"version": "6.8.1",
	"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.8.1.tgz",
	"integrity": "sha512-eqxCp82P+JfqL683wwsL73XmFs1eG6qjw+RD3YHx+Jll1r0jNd4dh8QG9NYAeNGA/hnZjeEDgtTskgJULbxpWQ==",
	"requires": {
		"fast-deep-equal": "^2.0.1",
		"fast-json-stable-stringify": "^2.0.0",
		"json-schema-traverse": "^0.4.1",
		"uri-js": "^4.2.2"
	}
},

https://stackoverflow.com/a/48524488

@ivangajic, what’s the line in the file? i don’t found 😢 I have the same issue with my angular 7 project

That’s 64 and 65

OK “resolutions” trick posted by @tyteen4a03 works

For those who “resolutions” method doesn’t work, for some reason, just explicitly define “ajv”: “6.8.1” in your package.json dependencies.

Worked for me, npm uninstall ajv npm install ajv@6.8.1

Thank you for this 😄

@jaydenseric I disagree strongly for actively maintained projects with lots of dependents. I added some tooling to help automate maintenance to keep dependencies up-to-date without risking breaking downstream projects.

Dependency updates can be maintained automatically by something like the renovate bot, or pseudo-manually using updtr.

I think threads like this one are ample evidence of the other side of the cost argument.

Failing to pin dependencies in a popular library is also a fairly serious security risk.

Consumers use package-lock.json to lock down their projects once all dependencies are tested to be in a working state.

This doesn’t help fresh installs.

Or add this to your package.json:

  "resolutions": {
    "ajv": "6.8.1"
  }

Seems so simple I would love it to work, but getting same error, anything else I should look at?

Have you reinstalled your packages with npm install? ;p

I’ve created a minimal reproduction repository: https://github.com/acro5piano/webpack-issues-8768

It is fixed so let’s wait a little more:) https://github.com/epoberezkin/ajv/pull/943

Worked for me, npm uninstall ajv npm install ajv@6.8.1

Also working for me. On another note, look at all us cool guys working on a Saturday night. lol

@youngzaphod Yes, I saw the same error, and then installed yarn. I’m glad you also solved the problem in one way or another!

@youngzaphod Please see updated comment for npm (or switch to Yarn)

Damn, I tried all that, went over to https://github.com/rogeriochaves/npm-force-resolutions and followed instructions there, and now I’m getting a “Cannot find module uri-js” error. Looks like the original error is gone though - progress!

I had the same problem. For me it only worked after installing yarn: https://yarnpkg.com/lang/en/docs/install/#debian-stable

Then run yarn.

@youngzaphod Please see updated comment for npm (or switch to Yarn)

@jackturnbull Thanks - I was just about to clarify.

@JesusViveros12 node_modules/ajv/lib/keyword.js 64 and 65