cypress run 抛出 Webpack 编译错误,但 cypress open 能够正常运行

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

Cypress 从 UI 完美运行,但无法使用

cypress run

通过 CI 运行

当我尝试运行它时,出现以下错误:

Oops...we found an error preparing this test file:

  > cypress\support\e2e.ts

The error was:

Error: Webpack Compilation Error
./node_modules/@aws-amplify/core/lib-esm/Signer.js

该错误实际上非常长,但它只是列出了后续的一系列其他故障。如果有需要的话我会补充的。

有人知道发生了什么事吗?我可以提供哪些额外信息?

谢谢!

cypress
1个回答
0
投票

这里的问题是 Signer.js 正在使用 ??需要将其转译为 cypress 才能使用的合并运算符。为了解决这个问题,我必须创建一个 .babelrc 文件,如下所示:

{
    "presets": ["@babel/preset-env"],
    "plugins": ["@babel/plugin-transform-nullish-coalescing-operator"]
}

并将以下代码包含在 cypress 配置 e2e->setupNodeEvents 函数中

    delete defaults.webpackOptions.module.rules[0].use[0].options.presets;
    defaults.webpackOptions = {
        ...defaults.webpackOptions,
        resolve: {
            fallback: {
                stream: require.resolve('stream-browserify'),
                'process/browser': require.resolve('process/browser'),
            },
        },
        plugins: [
            new ProvidePlugin({
                process: 'process/browser',
                Buffer: ['buffer', 'Buffer'],
            }),
        ],
    };
    on('file:preprocessor', webpackPreprocessor(defaults));

上面的代码改变了默认的 webpack 行为。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.