Cucumber [错误] 无法解析“node:perf_hooks”

问题描述 投票:0回答:1

我最近将cypress9升级到11,当我开始使用

npx cypress open

运行测试时我没有遇到任何问题。

当我开始使用时:

npx cypress run

它返回给我以下错误:

✘ [ERROR] Could not resolve "node:perf_hooks"

    node_modules/@cucumber/cucumber/lib/time.js:27:34:
      27 │ const node_perf_hooks_1 = require("node:perf_hooks");
         ╵                                   ~~~~~~~~~~~~~~~~~

  The package "node:perf_hooks" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

Error: Build failed with 1 error:
node_modules/@cucumber/cucumber/lib/time.js:27:34: ERROR: Could not resolve "node:perf_hooks"
    at failureErrorWithLog (/node_modules/esbuild/lib/main.js:1636:15)
    at /node_modules/esbuild/lib/main.js:1048:25
    at runOnEndCallbacks (/node_modules/esbuild/lib/main.js:1471:45)
    at buildResponseToResult (/node_modules/esbuild/lib/main.js:1046:7)
    at /node_modules/esbuild/lib/main.js:1075:16
    at responseCallbacks.<computed> (/node_modules/esbuild/lib/main.js:697:9)
    at handleIncomingPacket (/node_modules/esbuild/lib/main.js:752:9)
    at Socket.readFromStdout (/node_modules/esbuild/lib/main.js:673:7)
    at Socket.emit (node:events:518:28)
    at Socket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Socket.Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

我担心我缺少一些polyfill插件,我当前的插件是:

const createEsbuildPlugin = require('@badeball/cypress-cucumber-preprocessor/esbuild');
const { NodeModulesPolyfillPlugin } = require('@esbuild-plugins/node-modules-polyfill');
const nodePolyfills = require('@esbuild-plugins/node-modules-polyfill').NodeModulesPolyfillPlugin;

...

  on(
    'file:preprocessor',
    createBundler({
      plugins: [NodeModulesPolyfillPlugin(), nodePolyfills(), createEsbuildPlugin.default(config)],
    }),
  );


cucumber cypress
1个回答
0
投票

最后,我解决了在我的步骤定义文件之一中删除 cypress.config.ts 的导入问题。我正在做类似的事情:

import base from '../../../../cypress.config'; // WRONG

这是绝对错误的,这为我解决了所有错误,例如:

[ERROR] Could not resolve "fs"
[ERROR] Could not resolve "fs/promises"
[ERROR] Could not resolve "stream"
[ERROR] Could not resolve "stream/promises"
[ERROR] Could not resolve "console"
[ERROR] Could not resolve "crypto"
...
etc.

我得到阅读这个答案的提示。

© www.soinside.com 2019 - 2024. All rights reserved.