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

DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated #12035

Open
JackoPham opened this issue Feb 9, 2022 · 100 comments
Open

DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated #12035

JackoPham opened this issue Feb 9, 2022 · 100 comments

Comments

@JackoPham
Copy link

I got a warning when npm start.
Please help me solve the problem.

(node:1681) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use node --trace-deprecation ... to show where the warning was created)
(node:1681) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

@linzhipeng98
Copy link

#11860

@Cyebukayire
Copy link

I'm having the same warning too
Any solution to this?

@johnnychengchj123
Copy link

me too

I'm having the same warning too Any solution to this?

@imransilvake
Copy link

same issue

@iiaan
Copy link

iiaan commented Mar 10, 2022

i have the same problem

@yousefalkhatibDev
Copy link

I thought i was the only one. but let me ask something is this error has to do with the ERR_CONNECTION_REFUSED error?

@khizar-hayyat-72
Copy link

Same Error here.

@nurzhanx
Copy link

Same error in docker container. Docker version is 20.10.12, base image is node:alpine

@gars150387
Copy link

I am getting the same error:

"(node:9112) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use node --trace-deprecation ... to show where the warning was created)
(node:9112) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."

@oxicot
Copy link

oxicot commented Mar 17, 2022

The same thing here after upgrade to ..... "react-scripts": "^5.0.0" (Node 16.*)


$ npm start

test@0.1.0 start
react-scripts start

(node:21944) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use node --trace-deprecation ... to show where the warning was created)

(node:21944) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
Starting the development server...

Compiled successfully!

webpack 5.70.0 compiled successfully in 18347 ms

@nspool
Copy link

nspool commented Mar 25, 2022

Is this a duplicate of #11860 ?

@gars150387
Copy link

This warning disappeared using the repair option in the node.js file. It worked for me


I got a warning when npm start. Please help me solve the problem.

(node:1681) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. (Use node --trace-deprecation ... to show where the warning was created) (node:1681) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

@HaseebullahMemon
Copy link

i am facing node(8868) type of error. Please help me solve the problem
(node:8868) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE]
DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use node --trace-deprecation ... to show where the warning was created)
(node:8868) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

@SohelTanbir
Copy link

I got also the same warning!
please any solution available ?
(node:11648) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option

@anveshiano
Copy link

I am facing the same issue

@kojidev
Copy link

kojidev commented Mar 27, 2022

Would you all stop spamming? What is the purpose of you writing that you have the same issue? Will that fix the issue quicker? Subscribe to the issue and shut up

@alekennedy
Copy link

I have de same error with node 17-slim image in docker but in my computer I have node 17.7.0 and doesn't has the warning

htbkoo added a commit to htbkoo/personal-portfolio that referenced this issue Apr 5, 2022
Known issues:
1. `npm start` variable `BROWSER` is not working: facebook/create-react-app#11873
2. `[DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Ple
    ase use the 'setupMiddlewares' option.`: facebook/create-react-app#12035
htbkoo added a commit to htbkoo/personal-portfolio that referenced this issue Apr 5, 2022
Known issues:
1. `npm start` variable `BROWSER` is not working: facebook/create-react-app#11873
2. `[DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Ple
    ase use the 'setupMiddlewares' option.`: facebook/create-react-app#12035
@SwatiTParshuramkar
Copy link

(node:39133) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[1] (Use node --trace-deprecation ... to show where the warning was created)
[1] (node:39133) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

any solution for this warning?

@RussellOsiemo
Copy link

I have the same issue

@dear983604
Copy link

This warning disappeared using the repair option in the node.js file. It worked for me

I got a warning when npm start. Please help me solve the problem.
(node:1681) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. (Use node --trace-deprecation ... to show where the warning was created) (node:1681) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

What did you do?

@FrancescoVarsallona
Copy link

FrancescoVarsallona commented Apr 11, 2022

Deleting node_modules and run npm install has fixed for me. Probably some dependency has to be update

@SwatiTParshuramkar
Copy link

SwatiTParshuramkar commented Apr 14, 2022 via email

@MSSPL-KamalenduGarai
Copy link

I am getting same warnings in multiple systems which have been installed at different point of time. I have tried removing and installing fresh did not fix the issue. My environment is Node 16.13.1, NPM 8.3.0

@RichardHogg
Copy link

My way of solving this was... npm run build, then npm install -g serve,
npx serve -s build.
I couldn't figure out the webpack shit!! and the problem lied with the npm start so instead I used npx serve -s build... hope it helps!

@Chan3377
Copy link

Thank Richard! It's working well

@Monmoy042
Copy link

I have got also the same problem. What is the best solution for this?

@Gabriel-Pereira1788
Copy link

Obrigado Ricardo! Está funcionando bem

npx server does not dynamically update on mine. is yours updating the changes in the project automatically?

@Jorge-Ortiz-M
Copy link

Jorge-Ortiz-M commented May 17, 2022

I updated my npm version from linux. You can type sudo npm update -g npm.
That fix the same issue. After updated the npm version, I created a react app npx create-react-app myapp, cd myapp and run the command npm start and it worked. I hope you can solve it.

@ChromeQ
Copy link

ChromeQ commented Jan 5, 2023

Duplicate of #11860 - that answer is bad, don't do that, see my comment on the answer in the stack overflow and also on the other issue

@Gretchenchen
Copy link

@fpadularrosa
Copy link

https://bobbyhadz.com/blog/deprecationwarning-onaftersetupmiddleware-option-is-deprecated
Your welcome, guys/girls

@ChromeQ
Copy link

ChromeQ commented Jan 21, 2023

Your write-up details editing node_modules files, this is a really bad idea and you mention it is temporary but you don't make enough of a point on this in my opinion. Ejecting is a non-reversable action which you don't mention. I'd question if it is really worth ejecting to get rid of a deprecation warning. Remember this is a deprecation WARNING so nothing is broken, and you can safely ignore it, and I'm sure create-react-app will update this in a future version.

If it really bothers you so much there are other solutions, patch-package is a better way to edit node_modules, you could also look into editing it via craco or customize-cra.

Please people, don't take the advise here. It is bad advise.

@dastan132
Copy link

I got a warning when npm start. Please help me solve the problem.

(node:1681) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. (Use node --trace-deprecation ... to show where the warning was created) (node:1681) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

@Mehady05
Copy link

(node:14236) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use node --trace-deprecation ... to show where the warning was created)
(node:14236) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

@ANTAR-NANDI
Copy link

add this in your package.json file
"overrides": {
"autoprefixer": "10.4.5"
}
npm install

@ANTAR-NANDI
Copy link

(node:14236) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. (Use node --trace-deprecation ... to show where the warning was created) (node:14236) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

"overrides": {
"autoprefixer": "10.4.5"
}
npm install

@PranjayVats
Copy link

(node:14236) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. (Use node --trace-deprecation ... to show where the warning was created) (node:14236) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

"overrides": { "autoprefixer": "10.4.5" } npm install

Though this is not working for me yet I want to know how you come up with this solution.

@DonRyu
Copy link

DonRyu commented Mar 30, 2023

I think this guys solution is correct

https://www.youtube.com/watch?v=ifSTp9WEHpo

After I saw this youtube, problem is solved

@AthulKkumar
Copy link

run the command in the shell "npm update" it will work

@AthulKkumar
Copy link

(node:39133) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. [1] (Use node --trace-deprecation ... to show where the warning was created) [1] (node:39133) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

any solution for this warning?

use "npm update " command in the shell

@akashutosh77
Copy link

npm update worked for me

@renerlemes
Copy link

npm update or yarn upgrade not worked for me

@radthenone
Copy link

its funny, your tips not work when i have develop server automated create for all develops hidding node_modules, this is not a result

@MartinBarker
Copy link

Would you all stop spamming? What is the purpose of you writing that you have the same issue? Will that fix the issue quicker? Subscribe to the issue and shut up

I have the same issue

@FaroJoaoFaro
Copy link

I'm having the same warning too Any solution to this?

https://www.youtube.com/watch?v=ifSTp9WEHpo&ab_channel=DrVipinClasses

this solved it for me!! amazing and simple tutorial

@chnk8802
Copy link

I finally fixed this.If you are using yarn,just run yarn eject,then you should found '/config/webpackDevServer.config.js' file, Instead of onBeforeSetupMiddleware and onAfterSetupMiddleware, use the setupMiddlewares-property.Like this before:

onBeforeSetupMiddleware(devServer) {
      // Keep `evalSourceMapMiddleware`
      // middlewares before `redirectServedPath` otherwise will not have any effect
      // This lets us fetch source contents from webpack for the error overlay
      devServer.app.use(evalSourceMapMiddleware(devServer));

      if (fs.existsSync(paths.proxySetup)) {
        // This registers user provided middleware for proxy reasons
        require(paths.proxySetup)(devServer.app);
      }
    },
    onAfterSetupMiddleware(devServer) {
      // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
      devServer.app.use(redirectServedPath(paths.publicUrlOrPath));

      // This service worker file is effectively a 'no-op' that will reset any
      // previous service worker registered for the same host:port combination.
      // We do this in development to avoid hitting the production cache if
      // it used the same host and port.
      // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
      devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
    },

after:

setupMiddlewares: (middlewares, devServer) => {
      if (!devServer) {
        throw new Error('webpack-dev-server is not defined')
      }

      if (fs.existsSync(paths.proxySetup)) {
        require(paths.proxySetup)(devServer.app)
      }

      middlewares.push(
        evalSourceMapMiddleware(devServer),
        redirectServedPath(paths.publicUrlOrPath),
        noopServiceWorkerMiddleware(paths.publicUrlOrPath)
      )

      return middlewares;
    },

but it don't work when you host the server cuz you cant change it there as this must be done in node modules

@satya4satyanm
Copy link

I finally fixed this.If you are using yarn,just run yarn eject,then you should found '/config/webpackDevServer.config.js' file, Instead of onBeforeSetupMiddleware and onAfterSetupMiddleware, use the setupMiddlewares-property.Like this before:

onBeforeSetupMiddleware(devServer) {
      // Keep `evalSourceMapMiddleware`
      // middlewares before `redirectServedPath` otherwise will not have any effect
      // This lets us fetch source contents from webpack for the error overlay
      devServer.app.use(evalSourceMapMiddleware(devServer));

      if (fs.existsSync(paths.proxySetup)) {
        // This registers user provided middleware for proxy reasons
        require(paths.proxySetup)(devServer.app);
      }
    },
    onAfterSetupMiddleware(devServer) {
      // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
      devServer.app.use(redirectServedPath(paths.publicUrlOrPath));

      // This service worker file is effectively a 'no-op' that will reset any
      // previous service worker registered for the same host:port combination.
      // We do this in development to avoid hitting the production cache if
      // it used the same host and port.
      // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
      devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
    },

after:

setupMiddlewares: (middlewares, devServer) => {
      if (!devServer) {
        throw new Error('webpack-dev-server is not defined')
      }

      if (fs.existsSync(paths.proxySetup)) {
        require(paths.proxySetup)(devServer.app)
      }

      middlewares.push(
        evalSourceMapMiddleware(devServer),
        redirectServedPath(paths.publicUrlOrPath),
        noopServiceWorkerMiddleware(paths.publicUrlOrPath)
      )

      return middlewares;
    },

but it don't work when you host the server cuz you cant change it there as this must be done in node modules

How we will edit the code insode node-modules on deployment pipeline

@tamim-jr
Copy link

tamim-jr commented Sep 6, 2023

Follow this:
Go React Project file(my-app)> node_modile>react-scripts>config>webpackDevServer.config.js>then change this way:

DeprecationWarning Solution:

(node:2772) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning:
'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use node --trace-deprecation ... to show where the warning was created) (node:2772)
[DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning:
'onBeforeSetupMiddleware'option is deprecated. Please use the 'setupMiddlewares' option.

Error code like this: (select and remove it)

onBeforeSetupMiddleware(devServer) {
// Keep evalSourceMapMiddleware
// middlewares before redirectServedPath otherwise will not have any effect
// This lets us fetch source contents from webpack for the error overlay
devServer.app.use(evalSourceMapMiddleware(devServer));

if (fs.existsSync(paths.proxySetup)) {
// This registers user provided middleware for proxy reasons
require(paths.proxySetup)(devServer.app);
}

},
onAfterSetupMiddleware(devServer) {
// Redirect to PUBLIC_URL or homepage from package.json if url not match
devServer.app.use(redirectServedPath(paths.publicUrlOrPath));

// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// We do this in development to avoid hitting the production cache if
// it used the same host and port.
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));

},

Change to this: (past it on there)

setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined')
}

if (fs.existsSync(paths.proxySetup)) {
    require(paths.proxySetup)(devServer.app)
}

middlewares.push(
    evalSourceMapMiddleware(devServer),
    redirectServedPath(paths.publicUrlOrPath),
    noopServiceWorkerMiddleware(paths.publicUrlOrPath)
)

return middlewares;

},

https://github.com/tamim-jr/onAfterSetupMiddleware-option-is-deprecated./blob/main/src/Solution.txt

@anhtuank7c
Copy link

I did npm remove react-scripts --force and then npm add -D react-scripts --force
🎉 it works.

@GCE333
Copy link

GCE333 commented Jan 5, 2024

It seems like Create React App is dead and this issue will never be fixed. The best solution is to use Vite instead.

@JuntaoXu
Copy link

JuntaoXu commented Mar 1, 2024

removing the following code from node_modules\react-scripts\config\webpackDevServer.config.js made the warning go away

onBeforeSetupMiddleware(devServer) {
  // Keep `evalSourceMapMiddleware`
  // middlewares before `redirectServedPath` otherwise will not have any effect
  // This lets us fetch source contents from webpack for the error overlay
  devServer.app.use(evalSourceMapMiddleware(devServer));
  
  if (fs.existsSync(paths.proxySetup)) {
    // This registers user provided middleware for proxy reasons
    require(paths.proxySetup)(devServer.app);
  }
},
onAfterSetupMiddleware(devServer) {
  // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
  devServer.app.use(redirectServedPath(paths.publicUrlOrPath));
  
  // This service worker file is effectively a 'no-op' that will reset any
  // previous service worker registered for the same host:port combination.
  // We do this in development to avoid hitting the production cache if
  // it used the same host and port.
  // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
  devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
},

@JohnMaxwellDistinti
Copy link

JohnMaxwellDistinti commented Mar 3, 2024

Hi All,

Please refer to this article for an alternative snippet to "onBeforeSetupMiddleware" and "onAfterSetupMiddleware" within
node_modules/react-scripts/config/webpackDevServer.config.js:

https://discuss.codecademy.com/t/react-app-error/779264/2

This has fixed the error for me! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests