ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
https://ajv.js.org
MIT License
13.85k stars 878 forks source link

NPM: 6.9.0 AJV Commit causing failure to execute node_modules (multiple dependencies affected i.e. ESLint and WebPack Loaders) #941

Closed caldempsey closed 5 years ago

caldempsey commented 5 years ago

What version of Ajv are you using? Does the issue happen if you use the latest version?

Latest version (6.9.0 release I believe)

Ajv options object

node_modules/ajv/lib/keyword.js:65
      throw new Error('custom keyword definition is invalid: '  + this.errorsText(validateDefinition.errors));
      ^

Error: custom keyword definition is invalid: data.errors should be boolean
    at Ajv.addKeyword (/home/mmacheerpuppy/git/fsa/react-application/node_modules/ajv/lib/keyword.js:65:13)
    at module.exports (/home/mmacheerpuppy/git/fsa/react-application/node_modules/ajv-errors/index.js:10:7)
    at Object.<anonymous> (/home/mmacheerpuppy/git/fsa/react-application/node_modules/schema-utils/src/validateOptions.js:22:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

What results did you expect?

Expected to be able to build node_modules but experiencing above stacktrace.

Are you going to resolve the issue? Current workaround is to remove ESLint dependencies for NPM users, or if using YARN to resolve dependencies to forced version. It's also possible (with the addition of another dependency) to use NPM resolutions (see conversation).

Reproduction

Try using the following packages declaration. npm post install will fail to start. ESLint relies on AJV.

{
  "name": "food-standards",
  "version": "0.1.0",
  "private": true,
  "dependencies": {

    "axios": "^0.18.0",
    "bootstrap": "^4.2.1",
    "react": "^16.8.1",
    "react-dom": "^16.8.1",
    "react-scripts": "2.1.3",
    "reactstrap": "^7.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "axios-mock-adapter": "^1.16.0",
    "eslint": "5.6.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.1.1",
    "eslint-plugin-react": "^7.11.0",
    "react-testing-library": "^5.5.3"
  }
}
yooouuri commented 5 years ago

Same error for me #942 here using vue.js

caldempsey commented 5 years ago

Is there a workaround to use an earlier release?

yooouuri commented 5 years ago

I hope it get noticed fast

tetreault commented 5 years ago

Using nuxt for vue. My solve is doing npm i -d ajv@5.0.0 and i can run npm run dev again. This was a fresh nuxt project I started.

caldempsey commented 5 years ago

This is certainly related to the latest changes made in the commit history.

yooouuri commented 5 years ago

Add

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

to your package.json will create a work around (I am using yarn, don't know if it will work for npm)

mcrawshaw commented 5 years ago

@epoberezkin can we roll back?

velocity-360 commented 5 years ago

Can confirm, this is happening for me too when scaffolding Vue JS projects. Currently on Vue CLI 3.4.0, Mac OS 10.13.4. Please fix soon as this is causing serious delays.

yooouuri commented 5 years ago

@velocity-360 see my comment, use the work around! 😄

csvan commented 5 years ago

Seeing the same thing when using latest storybook 4.1, reproducible by simply running the bin build-storybook included in the same package. This entirely breaks a very large ecosystem.

Error: custom keyword definition is invalid: data/errors should be boolean
    at Ajv.addKeyword (/home/csvan/IdeaProjects/pros-ui-components/module/node_modules/ajv/lib/keyword.js:66:13)
    at module.exports (/home/csvan/IdeaProjects/pros-ui-components/module/node_modules/ajv-errors/index.js:10:7)
    at Object.<anonymous> (/home/csvan/IdeaProjects/pros-ui-components/module/node_modules/schema-utils/src/validateOptions.js:22:1)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)
    at Module.require (internal/modules/cjs/loader.js:663:17)
    at require (internal/modules/cjs/helpers.js:20:18)
velocity-360 commented 5 years ago

@velocity-360 see my comment, use the work around! 😄

@yooouuri thank you however, I am currently contracted to create a Vue tutorial series for a large educational software company and do not think it would be wise to kick off the series with a work-around immediately on the first step. I will wait for resolution.

yooouuri commented 5 years ago

@velocity-360 makes sense

caldempsey commented 5 years ago

@velocity-360 I'm trying to write a technical test for a job interview in React! :rofl:

richard-karp commented 5 years ago

lol @mmacheerpuppy exact same situation for me

caldempsey commented 5 years ago

@rickyTony I spent some time debugging and it seems like latest AJV is a dependency for ESLint which may produce a collision. You can use npm ls ajv to check this out.

viankakrisna commented 5 years ago

workaround for yarn users: add

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

to your package.json and re run yarn install

viankakrisna commented 5 years ago

looks like https://github.com/epoberezkin/ajv/issues/941#issuecomment-462087631 beat me to that 😅

richard-karp commented 5 years ago

@mmacheerpuppy I kinda ran out of time for the day debugging, so hopefully it's fixed when I get back to it tomorrow

gregoriB commented 5 years ago
  "dependencies": {
    "react": "^16.8.1",
    "react-dom": "^16.8.1",
    "react-scripts": "2.1.3",
    "ajv": "6.8.1"
  }

this worked for me using npm

andrewtet commented 5 years ago

@gregoriB I'm using create-react-app and unfortunately, I'm still getting the error after adding that 😞

viankakrisna commented 5 years ago

https://stackoverflow.com/questions/52416312/npm-equivalent-of-yarn-resolutions

caldempsey commented 5 years ago

@sky-coding You say that as if we don't have dependency chains on the back-end! @andrewtet can you kindly show your package.json?

gregoriB commented 5 years ago

@andrewtet did you run npm install afterwards?

viankakrisna commented 5 years ago

i think npm users can use this workaround https://github.com/rogeriochaves/npm-force-resolutions

caldempsey commented 5 years ago

Can confirm for React users it's ESLint and ESLint addons which are causing the issue in the dependency chain. Removing these and running npm install && npm start was sufficient to get me back on development.

{    
    "eslint": "5.6.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.1.1",
    "eslint-plugin-react": "^7.11.0",
}

So if you're in a hurry to get back on it, its time to get bare with React!

viankakrisna commented 5 years ago

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
andrewtet commented 5 years ago

@gregoriB Yeah, I ran npm i after adding "ajv": "6.8.1" to my package.json and it didn't work.

I tried again with "ajv": "6.8.1" in my package.json and ran rm -rf node_modules, npm cache clean --force, and then npm i and that did the trick. I've now got create-react app up and running.

gregoriB commented 5 years ago

@andrewtet yeah I just did the it "proper" way too. Not sure why the other way worked for me and not you though

rusye commented 5 years ago

I fixed this issue by resorting to an old version that I knew worked. Ran this npm install --save ajv@6.6.2

ChuntaoLu commented 5 years ago

@ChuntaoLu You say that as if we don't have dependency chains on the back-end! @andrewtet can you kindly show your package.json?

Wrong @ ?

caldempsey commented 5 years ago

@ChuntaoLu yes, sorry!

aaaguirrep commented 5 years ago

I have applied the workaround and it worked. Thanks.

cenfun commented 5 years ago

same issue node_modules\ajv\lib\keyword.js:65 throw new Error('custom keyword definition is invalid: ' + this.errorsText(validateDefinition.errors));

my solution is:

"dependencies": { "ajv": "6.8.1" }, "resolutions": { "ajv": "6.8.1" }

fkleuver commented 5 years ago

@epoberezkin I proposed a temporary fix which, hopefully, fixes the problem in dependent packages and removes the need for a full rollback. Let me know if you see any other issues regarding this. Perhaps you prefer a different solution, that's fine too. I'm just trying to help speed up the resolution

puiiyuen commented 5 years ago

For vue.js, it still doesn't work. There are too many dependencies that we cannot fix them one by one

audiolion commented 5 years ago

it is 3:30am london time, so a few more hours before @epoberezkin wakes up and releases a new version, time to go do something else for a bit!

fkleuver commented 5 years ago

Released right before going to bed, I figured as much. Typical :)

TheLarkInn commented 5 years ago

Hey @epoberezkin we have reported upstream workaround in our linked issue webpack/webpack#8768 so hopefully this reduces the chatter while this is being tackled by your team or other AJV contributors.

If there is anything we can do to help, let us know. - webpack team

epoberezkin commented 5 years ago

Thanks for the patience, going to fix https://github.com/epoberezkin/ajv/commit/7079aed19599fd13c95412b181fd2c08feb1debb - I think I know what the issue is.

errors can also be "full"...

epoberezkin commented 5 years ago

released 6.9.1

cenfun commented 5 years ago

released 6.9.1

thanks, just test with ajv@6.9.1 and it works now.

epoberezkin commented 5 years ago

Please let me know if somebody is still affected. The validation of custom keyword was simply incorrect, and now it is fixed. But it is still a bit more restrictive than it was - it would only fail though if e.g. somebody used 0 instead of false, which seems unlikely.

epoberezkin commented 5 years ago

It probably is possible to make travis CI run tests of some dependencies against the new tags (e.g. webpack and eslint).

csvan commented 5 years ago

@epoberezkin thanks for the fix!

epoberezkin commented 5 years ago

closing