Error when running npm run develop TypeError Yup.test is not a function

System Information
  • Strapi Version: latest
  • Operating System: windows 10
  • Database: sqlite
  • Node Version: 18.17.1
  • NPM Version: 10.0.0
  • Yarn Version:

I was trying to use postgreSql database, after running all the configuration, on running npm run develop, I got this error.
C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\strapi\lib\serviceregister-middlewares.js:53
return yup.test(() => false);
^

TypeError: yup.test is not a function
at Lazy.builder (C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\strapi\lib\services\server\register-middlewares.js:53:16)
at Lazy._resolve (C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\Lazy.js:23:25)
at Lazy.validate (C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\Lazy.js:41:17)
at tests. (C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\array.js:120:43)
at runTests (C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\util\runTests.js:39:5)
at C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\array.js:123:29
at C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\util\runTests.js:17:5
at runTests (C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\util\runTests.js:35:100)
at C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\schema.js:248:29
at C:\Users\user\Documents\Build\Laurabon_foundation\my-project\node_modules\strapi\utils\node_modules\yup\lib\util\runTests.js:17:5

Node.js v18.17.1

I have tried walking back all the changes I made, I even updated the yup version to the latest, I also upgraded my strapi to the latest version.

here is my register-middlewares.js file
‘use strict’;

const { yup } = require(‘strapi/utils’);

const { resolveMiddlewares } = require(‘./middleware’);

/**

  • typedef {import(‘…/…/’).Strapi} Strapi
  • typedef {Array<string|{name?: string, resolve?: string, config: any}>} MiddlewaresConfig
  • typedef {Array<{name: string, hanlder: Function}>} Middlewares
    */

const defaultConfig = [
‘strapi::errors’,
‘strapi::security’,
‘strapi::cors’,
‘strapi::poweredBy’,
‘strapi::session’,
‘strapi::logger’,
‘strapi::query’,
‘strapi::body’,
‘strapi::favicon’,
‘strapi::public’,
];

const requiredMiddlewares = [
‘strapi::errors’,
‘strapi::security’,
‘strapi::cors’,
‘strapi::query’,
‘strapi::body’,
‘strapi::public’,
‘strapi::favicon’,
];

const middlewareConfigSchema = yup.array().of(
yup.lazy((value) => {
if (typeof value === ‘string’) {
return yup.string().required();
}

if (typeof value === 'object') {
  return yup
    .object({
      name: yup.string(),
      resolve: yup.string(),
      config: yup.mixed(),
    })
    .required()
    .noUnknown();
}

return yup.test(() => false);

})
);

/**

  • Register middlewares in router
  • @param {Strapi} strapi
    */
    const registerApplicationMiddlewares = async (strapi) => {
    const middlewareConfig = strapi.config.get(‘middlewares’, defaultConfig);

await validateMiddlewareConfig(middlewareConfig);

const middlewares = await resolveMiddlewares(middlewareConfig, strapi);

checkRequiredMiddlewares(middlewares);

// NOTE: exclude middlewares that return nothing.
// this is used for middlewares that only extend the app only need to be added in certain conditions
for (const middleware of middlewares) {
strapi.server.use(middleware.handler);
}
};

/**
*

  • @param {MiddlewaresConfig} config
    */
    const validateMiddlewareConfig = async (config) => {
    try {
    await middlewareConfigSchema.validate(config, { strict: true, abortEarly: false });
    } catch (error) {
    throw new Error(
    ‘Invalid middleware configuration. Expected Array<string|{name?: string, resolve?: string, config: any}.’
    );
    }
    };

/**

  • Check if some required middlewares are missing in configure middlewares
  • @param {Middlewares} middlewares
    */
    const checkRequiredMiddlewares = (middlewares) => {
    const missingMiddlewares = requiredMiddlewares.filter((name) => {
    return middlewares.findIndex((mdl) => mdl.name === name) === -1;
    });

if (missingMiddlewares.length > 0) {
throw new Error(
Missing required middlewares in configuration. Add the following middlewares: "${missingMiddlewares.join( ', ' )}".
);
}
};

module.exports = registerApplicationMiddlewares;

I have been on this for days now, please i need help

hello, i have the same problem too, did you fix this?

I’ve been working on this for a few days. Please let me know if you’ve already found the solution