运行 npm run make 时出现“类型错误:无法读取未定义的属性‘日期’”

Sta*_*ep1 9 javascript node.js reactjs electron electron-forge

我正在尝试对电子进行反应,尽管我遵循了该网站的说明:https ://dev.to/mandiwise/electron-apps-made-easy-with-create-react-app-and-电子铸造-560e

和这个网站(图标):https ://chasingcode.dev/blog/electron-generate-mac-windows-app-icons

每当我运行 npm run make 时都会出现此错误

$ npm run make

> electronforge@0.1.0 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! electronforge@0.1.0 make: `react-scripts build && electron-forge make`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electronforge@0.1.0 make script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

我不是制作这个节点模块的人,所以我不知道其中发生了什么,但它就是这样。

_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])
}
Run Code Online (Sandbox Code Playgroud)

正如我所说,我不是制作 formatLimit.js 的人,所以如果您有解决方案,请使其非常明显,以便我可以修复它。

我已经尝试过的事情:

删除节点模块并再次执行 npm install

谷歌搜索错误,但似乎没有人有我所遇到的确切错误,所以我无法真正使用他们的解决方案

将[名称]更改为[日期]仍然是相同的错误

小智 2

我在 Angular(12) 项目中遇到了同样的错误,并在我的案例 v.(^5.1.0) 中安装最新版本的“ajv-keywords”解决了问题!