Search code examples
javascriptnode.jsreactjselectronelectron-forge

"TypeError: Cannot read property 'date' of undefined" when running npm run make


I'm trying to get react to work with electron and even though i followed the instructions from this site: https://dev.to/mandiwise/electron-apps-made-easy-with-create-react-app-and-electron-forge-560e

and this site (for the icons): https://chasingcode.dev/blog/electron-generate-mac-windows-app-icons

Anytime I run npm run make i get this error

$ npm run make

> [email protected] make C:\StandaloneApps\electronforge
> react-scripts build && electron-forge make

these parameters are deprecated, see docs for addKeyword
these parameters are deprecated, see docs for addKeyword
these parameters are deprecated, see docs for addKeyword
C:\StandaloneApps\electronforge\node_modules\ajv-keywords\keywords\_formatLimit.js:63
    var format = formats[date]
                        ^

TypeError: Cannot read property 'date' of undefined
    at extendFormats (C:\StandaloneApps\electronforge\node_modules\ajv-keywords\keywords\_formatLimit.js:63:25)
    at defFunc (C:\StandaloneApps\electronforge\node_modules\ajv-keywords\keywords\_formatLimit.js:54:5)
    at defineKeywords (C:\StandaloneApps\electronforge\node_modules\ajv-keywords\index.js:17:22)
    at Object.<anonymous> (C:\StandaloneApps\electronforge\node_modules\schema-utils\dist\validate.js:64:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] make: `react-scripts build && electron-forge make`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] make script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I am not the one who made this node modules so I have no idea what's going on in it but here it is.

_formatLimit.js

'use strict'

var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i
var DATE_TIME_SEPARATOR = /t|\s/i

var COMPARE_FORMATS = {
  date: compareDate,
  time: compareTime,
  'date-time': compareDateTime
}

var $dataMetaSchema = {
  type: 'object',
  required: [ '$data' ],
  properties: {
    $data: {
      type: 'string',
      anyOf: [
        { format: 'relative-json-pointer' },
        { format: 'json-pointer' }
      ]
    }
  },
  additionalProperties: false
}

module.exports = function (minMax) {
  var keyword = 'format' + minMax
  return function defFunc(ajv) {
    defFunc.definition = {
      type: 'string',
      inline: require('./dotjs/_formatLimit'),
      statements: true,
      errors: 'full',
      dependencies: ['format'],
      metaSchema: {
        anyOf: [
          {type: 'string'},
          $dataMetaSchema
        ]
      }
    }

    ajv.addKeyword(keyword, defFunc.definition)
    ajv.addKeyword('formatExclusive' + minMax, {
      dependencies: ['format' + minMax],
      metaSchema: {
        anyOf: [
          {type: 'boolean'},
          $dataMetaSchema
        ]
      }
    })
    extendFormats(ajv)
    return ajv
  }
}


function extendFormats(ajv) {
  var formats = ajv._formats
  for (var name in COMPARE_FORMATS) {
    var format = formats[name]
    // the last condition is needed if it's RegExp from another window
    if (typeof format != 'object' || format instanceof RegExp || !format.validate)
      format = formats[name] = { validate: format }
    if (!format.compare)
      format.compare = COMPARE_FORMATS[name]
  }
}


function compareDate(d1, d2) {
  if (!(d1 && d2)) return
  if (d1 > d2) return 1
  if (d1 < d2) return -1
  if (d1 === d2) return 0
}


function compareTime(t1, t2) {
  if (!(t1 && t2)) return
  t1 = t1.match(TIME)
  t2 = t2.match(TIME)
  if (!(t1 && t2)) return
  t1 = t1[1] + t1[2] + t1[3] + (t1[4]||'')
  t2 = t2[1] + t2[2] + t2[3] + (t2[4]||'')
  if (t1 > t2) return 1
  if (t1 < t2) return -1
  if (t1 === t2) return 0
}


function compareDateTime(dt1, dt2) {
  if (!(dt1 && dt2)) return
  dt1 = dt1.split(DATE_TIME_SEPARATOR)
  dt2 = dt2.split(DATE_TIME_SEPARATOR)
  var res = compareDate(dt1[0], dt2[0])
  if (res === undefined) return
  return res || compareTime(dt1[1], dt2[1])
}

As I said I am not the one who made formatLimit.js so if you have the solution please make it really really obvious so i can fix it.

Things I've already tried:

deleting node modules and doing npm install again

googling the error but no one seems to have the exact error I have so I can't really use their solution

changing [name] to [date] still the same error


Solution

  • I had same error in our Angular(12) project and installing latest version of "ajv-keywords" in my case v.(^5.1.0) solve the issue!