代码之家  ›  专栏  ›  技术社区  ›  Stacklep1

运行npm run make时“TypeError:无法读取undefined的属性'date'”

  •  0
  • Stacklep1  · 技术社区  · 3 年前

    我试图对电子的工作做出反应,尽管我遵循了这个网站的说明: https://dev.to/mandiwise/electron-apps-made-easy-with-create-react-app-and-electron-forge-560e

    以及此网站(用于图标): https://chasingcode.dev/blog/electron-generate-mac-windows-app-icons

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

    $ 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.
    

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

    _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])
    }
    

    正如我所说的,我不是创建formatLimit.js的人,所以如果你有解决方案,请让它变得非常明显,这样我就可以修复它。

    我已经尝试过的事情:

    删除节点模块并重新进行npm安装

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

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

    0 回复  |  直到 3 年前