After updating dependencies I got problem with @craco (https://www.npmjs.com/package/@craco/craco) / react-scripts. Resulting in the error:
(node:14573) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE]
DeprecationWarning: ‘onAfterSetupMiddleware’ option is deprecated.
Please use the ‘setupMiddlewares’ option. (Usenode --trace-deprecation ...
to show where the warning was created) (node:14573) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE]
DeprecationWarning: ‘onBeforeSetupMiddleware’ option is deprecated.
Please use the ‘setupMiddlewares’ option.
Related issue: Cant load a react app after starting server
This seems to be a issue with the proxy settings in the node_modules/react-scripts/config/webpackDevServer.config.js
Tried resolving this issue by overriding my craco config.
my current config looks like this:
const CracoLessPlugin = require('craco-less');
const path = require('path');
const { EnvironmentPlugin } = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const evalSourceMap = require('react-dev-utils/evalSourceMapMiddleware');
const redirectServedPath = require('react-dev-utils/redirectServedPathMiddleware');
const noopServiceWorker = require('react-dev-utils/noopServiceWorkerMiddleware');
const fs = require('fs-extra');
module.exports = {
webpack: {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
openAnalyzer: false,
}),
new EnvironmentPlugin({
GIT_COMMIT_HASH: 'local-dev',
}),
],
alias: {
'@': path.resolve(__dirname, 'src/'),
},
},
devServer: (devServerConfig, { env, paths }) => {
devServerConfig = {
onBeforeSetupMiddleware: undefined,
onAfterSetupMiddleware: undefined,
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(
evalSourceMap(devServer),
redirectServedPath(paths.publicUrlOrPath),
noopServiceWorker(paths.publicUrlOrPath)
);
return middlewares;
},
};
return devServerConfig;
},
plugins: [{ plugin: CracoLessPlugin }],
eslint: {
enable: true,
mode: 'extends',
configure: {
extends: 'react-app',
rules: {
'react/jsx-pascal-case': 'off',
},
},
},
jest: {
configure: {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
},
},
};
additional information:
“@craco/craco”: “^7.1.0”
“react-scripts”: “^5.0.1”
“react”: “^18.2.0”,
Any got any clue why this override isn’t working?
Thx 🙂