Azure数据工厂-在Azure Devops管道中将Node更新为20失败:“this”参数必须是Performance的示例

voj3qocg  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(171)

我有一个管道创建根据:https://learn.microsoft.com/en-us/azure/data-factory/continuous-integration-delivery-improvements我试图更新节点版本到20.x:

- task: NodeTool@0
  inputs:
    versionSpec: '20.x'
  displayName: 'Install Node.js'

字符串
在package.json中

"dependencies":{
        "@microsoft/azure-data-factory-utilities":"^1.0.0"
    }


在验证阶段,我得到错误:YAML

TypeError [ERR_INVALID_ARG_TYPE]: The "this" argument must be an instance of Performance. Received an instance of Object
    at now (node:internal/perf/performance:139:5)


如何解决此问题?

x8diyxa7

x8diyxa71#

此问题的根本原因是Node.js更新破坏了now() API。以前从Node 16开始,您可以执行以下操作:

const now = perf_hooks.performance.now
const t0 = now()
for (i = 0; i < 1000000; i++)
  ;
console.log((now() - t0)/1000.0)

字符串
但在Node v18.13.0之前进行了测试,结果如下:

/home/ciro/main.js:1
const now = perf_hooks.performance.now
            ^

ReferenceError: perf_hooks is not defined
    at Object.<anonymous> (/home/ciro/main.js:1:13)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.13.0


在代码块中维护旧的API的工作替代方案是:

const { performance } = require('perf_hooks')
const now = performance.now.bind(performance)
const t0 = now()
for (i = 0; i < 1000000; i++)
  ;
console.log((now() - t0)/1000.0)


如果这来自您无法控制其来源的依赖项,则可以选择:

  • 尝试更新依赖项,希望开发人员已经修复了它
  • 降级你的Node.js。不理想。

其他定时方法在How do I measure the execution time of JavaScript code with callbacks?中描述:

相关问题