Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: patterns.reduce is not a function #404

Closed
MelaAxel opened this issue Jul 5, 2023 · 10 comments
Closed

TypeError: patterns.reduce is not a function #404

MelaAxel opened this issue Jul 5, 2023 · 10 comments
Milestone

Comments

@MelaAxel
Copy link

MelaAxel commented Jul 5, 2023

Environment

  • OS Version: Windows 11 Enterprise (22621.1848)
  • Node.js Version: 20.3.1
  • Cypress 12.16
  • @cypress/grep 3.15

Actual behavior

TypeError thrown starting today after Node and package updates

2023-07-05_13-55-12

Expected behavior

No error

Steps to reproduce

  1. launch cypress
  2. select e2e
  3. error thrown

Code sample

This is our cypress.config.js:

const { defineConfig } = require('cypress');

module.exports = defineConfig({
  e2e: {
    specPattern: 'cypress/e2e/**/*cy.js',
    setupNodeEvents(on, config) {
      require('@cypress/grep/src/plugin')(config);
      return config;
    },
  },
  env: {
    grepFilterSpecs: true,
  },
});

Error Details

node_modules\fast-glob\out\utils\pattern.js:131:21
  129 | exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
  130 | function expandPatternsWithBraceExpansion(patterns) {
> 131 |     return patterns.reduce((collection, pattern) => {
      |                     ^
  132 |         return collection.concat(expandBraceExpansion(pattern));
  133 |     }, []);
  134 | }
  135 | exports.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;

Stack trace

TypeError: patterns.reduce is not a function
    at Object.expandPatternsWithBraceExpansion (C:\Users\US26134\Git\WebUIAutomation\node_modules\fast-glob\out\utils\pattern.js:131:21)
    at processPatterns (C:\Users\US26134\Git\WebUIAutomation\node_modules\fast-glob\out\managers\tasks.js:27:34)
    at Object.generate (C:\Users\US26134\Git\WebUIAutomation\node_modules\fast-glob\out\managers\tasks.js:7:20)
    at getWorks (C:\Users\US26134\Git\WebUIAutomation\node_modules\fast-glob\out\index.js:91:31)
    at AsyncFunction.sync (C:\Users\US26134\Git\WebUIAutomation\node_modules\fast-glob\out\index.js:23:23)
    at AsyncFunction.module.exports.sync (C:\Users\US26134\Git\WebUIAutomation\node_modules\globby\index.js:151:42)
    at cypressGrepPlugin (C:\Users\US26134\Git\WebUIAutomation\node_modules\@cypress\grep\src\plugin.js:70:30)
    at setupNodeEvents (C:\Users\US26134\Git\WebUIAutomation\cypress.config.js:23:42)
    at C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_plugins.js:122:14
    at tryCatcher (C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\bluebird\js\release\util.js:16:23)
    at Function.Promise.attempt.Promise.try (C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\bluebird\js\release\method.js:39:29)
    at RunPlugins.load (C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_plugins.js:119:9)
    at RunPlugins.runSetupNodeEvents (C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_plugins.js:59:17)
    at EventEmitter. (C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_require_async_child.js:185:22)
    at EventEmitter.emit (node:events:511:28)
    at EventEmitter.emit (node:domain:489:12)
    at process. (C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\util.js:33:22)
    at process.emit (node:events:511:28)
    at process.emit (node:domain:489:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (C:\Users\US26134\AppData\Local\Cypress\Cache\12.16.0\Cypress\resources\app\node_modules\@cspotcode\source-map-support\source-map-support.js:745:40)
    at emit (node:internal/child_process:944:14)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
@alan-agius4
Copy link
Contributor

alan-agius4 commented Jul 6, 2023

I also came across this problem but infact it was an error from my side as in the ignore option I was passing a string instead of an array of strings.

@memodi
Copy link

memodi commented Jul 6, 2023

I am facing this error too. Until this is resolved, workaround is to fixate to particular version in package.json by adding below:

"resolutions": {
    "fast-glob": ">=3.2.9 <=3.2.12"
  }

@mrmlnc
Copy link
Owner

mrmlnc commented Jul 7, 2023

The public interface of this package does not support a string as the value for the ignore option since 2018 year (release). I do not consider this issue a bug in my package. It is a problem on the consumer side.

Right now the problem needs to be fixed on the cypress side.


Similar issues: #403

@samtsai
Copy link

samtsai commented Jul 7, 2023

The public interface of this package does not support a string as the value for the ignore option since 2018 year (release). I do not consider this issue a bug in my package. It is a problem on the consumer side.

Thanks @mrmlnc , looking into a fix: cypress-io/cypress#27231

@MelaAxel
Copy link
Author

Thanks all! Since this is a cypress-side issue, I'll close this out and watch for an update on the ticket @samtsai mentioned

@kaiserkiwi
Copy link

Why is this a cypress-side issue? I have the same issue in a project that has nothing to to with cypress.
The moment I write "fast-glob": ">=3.2.9 <=3.2.12", in my devDependencies everything works fine.

So I would assume that Version 3.3.0 has an issue here. Can we reopen this?

@mrmlnc
Copy link
Owner

mrmlnc commented Jul 13, 2023

This is not a cypress problem. It is the problem of every package that does not respect the public interface of that package. The public interface of this package does not support a string as the value for the ignore option since 2018 year (release). I want to say that all this time, using a string as a value was accidental.

I am willing to modify the public interface if the number of affected packages reaches dozens. For now, I prefer to keep the current implementation for codebase cleanliness.

@kaiserkiwi
Copy link

Technically I'm on your side, but it breaks stuff with a minor version. That's usually not how it should work.

According to Semver a minor version should a minor version »add functionality in a backward compatible manner«. That's not the case here. So technically this should be 4.0.0.

But I totally understand that's not your fault, that other packages use your package in a wrong way.

@mrmlnc
Copy link
Owner

mrmlnc commented Jul 14, 2023

That sounds pretty compelling to me. I plan to fix this issue and postpone the major change to the next major release.

@mrmlnc
Copy link
Owner

mrmlnc commented Jul 22, 2023

@mrmlnc mrmlnc closed this as completed Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants