exports is not defined webpack 5 babel 7 react-redux - react-native

i am trying to develop a react-native app with react-native-web, everything was working fine until i installed react-redux.
i get the following error in the console
bundle.web.js:9435 Uncaught ReferenceError: exports is not defined
at eval (extends.js:2:23)
at ./node_modules/#babel/runtime/helpers/esm/extends.js (bundle.web.js:132:1)
at __webpack_require__ (bundle.web.js:9432:33)
at fn (bundle.web.js:9619:21)
at eval (connect.js:1:657)
at ./node_modules/react-redux/es/components/connect.js (bundle.web.js:8203:1)
at __webpack_require__ (bundle.web.js:9432:33)
at fn (bundle.web.js:9619:21)
at eval (index.js:1:923)
at ./node_modules/react-redux/es/index.js (bundle.web.js:8333:1)
i tried some of the solutions that i found online, but i couldn't make it to work. i am not sure what i am doing wrong, or what i did to mess things up. any help would be appreciated
this is my webpack.config.cs
const path = require('path');
const webpack = require('webpack');
const appDirectory = path.resolve(__dirname, '../');
const imageLoaderConfiguration = {
test: /\.(gif|jpe?g|png|svg)$/,
use: {
loader: 'url-loader',
options: {
name: '[name].[ext]',
esModule: false,
},
},
};
module.exports = {
entry: [
"#babel/polyfill",
path.resolve(appDirectory, 'index.web.js'),
],
plugins: [
new webpack.DefinePlugin({ process: { env: {} } })
],
output: {
filename: 'bundle.web.js',
path: path.resolve(appDirectory, 'dist'),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader',
options: {
presets: [
'#babel/preset-react',
{
plugins: ['#babel/plugin-proposal-class-properties']
}
],
sourceType: 'unambiguous'
},
},
},
{
test: /\.ttf$/,
loader: "url-loader",
include: path.resolve(__dirname, "node_modules/react-native-vector-icons"),
}, imageLoaderConfiguration],
},
resolve: {
alias: {
'react-native$': 'react-native-web',
},
extensions: ['.web.js', '.js', '.jsx'],
},
};
and my package.json
{
"name": "awesomeproject",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint .",
"web": "webpack serve -d eval --mode development --config \"./web/webpack.config.js\" --inline --color --hot",
"build:web": "webpack --mode production --config \"./web/webpack.config.js\" --hot"
},
"dependencies": {
"#babel/preset-react": "^7.16.7",
"#react-native-community/checkbox": "^0.5.12",
"#react-navigation/bottom-tabs": "^6.3.1",
"#react-navigation/drawer": "^6.3.1",
"#react-navigation/native": "^6.0.8",
"#react-navigation/native-stack": "^6.5.0",
"#reduxjs/toolkit": "^1.8.2",
"axios": "^0.21.1",
"react": "17.0.1",
"react-dom": "^17.0.2",
"react-native": "0.64.2",
"react-native-gesture-handler": "^2.3.0",
"react-native-reanimated": "^2.4.1",
"react-native-safe-area-context": "^3.4.1",
"react-native-screens": "^3.13.1",
"react-native-vector-icons": "^9.1.0",
"react-native-web": "^0.16.5",
"react-redux": "^8.0.2",
"redux": "^4.2.0"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#babel/polyfill": "^7.12.1",
"#babel/runtime": "^7.12.5",
"#react-native-community/eslint-config": "^2.0.0",
"#redux-devtools/core": "^3.13.1",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-react-native-web": "^0.16.5",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "17.0.1",
"url-loader": "^4.1.1",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
},
"jest": {
"preset": "react-native-web"
},
"rnpm": {
"assets": [
".src/assets/fonts/"
]
}
}

Related

React Native - Unable to resolve module `node_modules/react/index.js/jsx-runtime`

I'm in the process of upgrading react native and I've been stuck on the following error for the past few days:
BUNDLE ./index.ts
error: Error: Unable to resolve module
monorepo/app/node_modules/react/index.js/jsx-runtime from monorepo/mobileChat/src/screens/index.tsx:
None of these files exist:
* node_modules/react/index.js/jsx-runtime(.native|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
* node_modules/react/index.js/jsx-runtime/index(.native|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
> 1 | import React from 'react'
2 | import { Navigation } from 'react-native-navigation'
3 | import { Provider } from 'react-redux'
4 | import getStore from 'shared/store'
at ModuleResolver.resolveDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:152:15)
at DependencyGraph.resolveDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/node-haste/DependencyGraph.js:264:43)
at Object.resolve (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/lib/transformHelpers.js:170:21)
at resolveDependencies (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:466:33)
at processModule (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:232:31)
at async addDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:361:18)
at async Promise.all (index 9)
at async processModule (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:279:3)
at async addDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:361:18)
at async Promise.all (index 3)
I'm trying to understand why the path is resolving to ...node_modules/react/index.js/jsx-runtime. I'm not what's causing the path to be created like this. the correct path should be ...node_modules/react/jsx-runtime.
Here is my package.json
{
"name": "mobileChat",
"workspaces": {
"nohoist": [
"jetifier",
"react-native",
"react-native/**",
"#react-native-community/**",
"react-native-navigation",
"react-native-onesignal",
"react-native-version-number",
"react-native-image-crop-picker",
"react-native-video",
"react-native-keyboard-aware-scroll-view",
"#sentry/**",
"#amplitude/react-native",
"react",
"#testing-library/react-native",
"#types/react-native"
]
},
"version": "3.22.0",
"private": true,
"scripts": {
"run-ios": "react-native run-ios",
"run-android": "react-native run-android",
"start": "node node_modules/react-native/local-cli/cli.js start",
"ts": "tsc --noEmit --jsx react-native --project tsconfig.json",
"ts:watch": "yarn ts --watch",
"test": "yarn jest",
"test:watch": "yarn jest --watch",
"version": "react-native-version --never-increment-build"
},
"dependencies": {
"#amplitude/react-native": "2.16.1",
"#babel/core": "^7.12.9",
"#babel/plugin-transform-runtime": "7.13.9",
"#babel/runtime": "7.12.5",
"#react-native-async-storage/async-storage": "1.15.17",
"#react-native-community/datetimepicker": "^3.5.2",
"#react-native-community/netinfo": "4.7.0",
"#react-native-community/push-notification-ios": "^1.10.0",
"#react-native-community/toolbar-android": "^0.2.1",
"#react-native-cookies/cookies": "6.0.11",
"#sentry/react-native": "4.6.1",
"#stream-io/flat-list-mvcp": "^0.10.1",
"linkify-it": "3.0.3",
"mdurl": "^1.0.1",
"prop-types": "^15.7.2",
"react": "18.1.0",
"react-native": "0.70.6",
"react-native-audio": "https://github.com/bloomapi/react-native-audio",
"react-native-bidirectional-infinite-scroll": "^0.3.3",
"react-native-deep-linking": "^2.2.0",
"react-native-get-random-values": "^1.8.0",
"react-native-image-crop-picker": "0.38.0",
"react-native-iphone-x-helper": "1.3.1",
"react-native-keyboard-aware-scroll-view": "0.9.5",
"react-native-linear-gradient": "2.5.6",
"react-native-navigation": "7.27.1",
"react-native-onesignal": "4.3.3",
"react-native-swipe-list-view": "^3.2.9",
"react-native-version-number": "0.3.6",
"react-native-video": "^6.0.0-alpha.3",
"react-redux": "7.2.2",
"redux": "4.0.5",
"redux-logger": "3.0.6",
"redux-persist": "4.10.2",
"rn-fetch-blob": "0.12.0",
"text-encoding-polyfill": "^0.6.7"
},
"devDependencies": {
"#babel/preset-env": "7.16.11",
"#testing-library/jest-native": "^4.0.1",
"#testing-library/react-hooks": "^7.0.1",
"#testing-library/react-native": "^8.0.0",
"#types/jest": "^26.0.23",
"#types/react": "^18.0.21",
"#types/react-native": "^0.70.6",
"#types/react-test-renderer": "18.0.0",
"babel-jest": "26.6.3",
"babel-plugin-module-resolver": "4.1.0",
"get-yarn-workspaces": "^1.0.2",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "0.72.3",
"react-native-version": "^4.0.0",
"react-test-renderer": "18.1.0",
"redux-devtools-extension": "^2.13.9",
"typescript": "^4.8.3"
}
}
Here's my metro.config.js
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* #format
*/
const path = require('path')
const getWorkspaces = require('get-yarn-workspaces')
const extraNodeModules = {
'mobile': path.resolve(__dirname, 'src'),
'components': 'mobile/components',
'screens': 'mobile/screens',
}
const workspaces = getWorkspaces(__dirname)
const watchFolders = [
path.resolve(__dirname, '..', 'node_modules'),
...workspaces.filter(dir => dir !== __dirname),
]
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
extraNodeModules,
},
watchFolders,
}
Here's my babel.config.js
const path = require('path')
module.exports = {
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
[
"module-resolver",
{
"extensions": [".ios.js", ".android.js", ".js", ".json"],
"alias": {
"react": require.resolve('react', { paths: [path.join(__dirname, './')] }),
'^react-native$': require.resolve('react-native', { paths: [path.join(__dirname, './')] }),
'^react-native/(.+)': ([, name]) => require.resolve(`react-native/${name}`, { paths: [path.join(__dirname, './')] }),
},
},
],
],
}
Been really stuck on this. Any help would greatly be appreciated.
I recently ran into the same issue when upgrading from expo SDK 45 to 46.
It turns out that completely removing the module-resolver from my babel.config.js file resolved the issue.
Even if you don't use expo, I still suggest you to investigate this way

Cannot read property 'bindings' of null Error React-Native Jest testing

I'm using Jest to unit test my react-native project, but after running npm test, I got this error:
Test suite failed to run
TypeError: /Users/walidramadan/lemonade-fashion/lemonade_mobile_client/src/screens/CartScreen.js: Cannot read property 'bindings' of null
Here's my configurations:
babel.config.js:
```module.exports = {
presets: ["#babel/preset-env", 'react-native'],
plugins: [
[
'module-resolver',
{
extensions: [
'.js',
'.jsx',
'.ts',
'.tsx',
'.android.js',
'.android.tsx',
'.ios.js',
'.ios.tsx',
],
root: ['.'],
},
],
[
'module:react-native-dotenv',
{
moduleName: '#env',
path: '.env'
}
]
]
};```
package.json:
```{
"name": "lemonade_mobile_client",
"jest": {
"verbose": true,
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation)"
],
"setupFilesAfterEnv": [
"<rootDir>/node_modules/riteway-jest/src/riteway-jest.js"
]
},
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest --config=jest.config.js",
"lint": "eslint ."
},
"dependencies": {
"#babel/core": "^7.13.16",
"#haskkor/react-native-recaptchav3": "^1.2.1",
"#invertase/react-native-apple-authentication": "^2.1.1",
"#lemonadefashion/imagekit": "^1.0.0",
"#lemonadefashion/recaptcha-actions": "^1.0.0",
"#react-native-community/checkbox": "^0.5.7",
"#react-native-community/masked-view": "^0.1.10",
"#react-native-community/picker": "^1.8.1",
"#react-navigation/bottom-tabs": "^5.11.9",
"#react-navigation/drawer": "^5.12.5",
"#react-navigation/native": "^5.9.4",
"#react-navigation/stack": "^5.14.4",
"axios": "^0.21.1",
"babel-plugin-module-resolver": "^4.1.0",
"babel-preset-react-native": "^4.0.1",
"native-base": "^2.15.2",
"react": "17.0.1",
"react-native": "0.64.0",
"react-native-check-box": "^2.1.7",
"react-native-dotenv": "^2.5.5",
"react-native-fbsdk-next": "^4.0.0",
"react-native-gesture-handler": "^1.10.3",
"react-native-linear-gradient": "^2.5.6",
"react-native-pager-view": "^5.1.3",
"react-native-picker-select": "^8.0.4",
"react-native-reanimated": "^2.1.0",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.1.0",
"react-native-tab-view": "^3.0.1",
"react-native-vector-icons": "^8.1.0",
"react-native-webview": "^11.3.2"
},
"devDependencies": {
"#babel/preset-env": "^7.13.15",
"#babel/runtime": "7.13.10",
"#react-native-community/eslint-config": "2.0.0",
"#testing-library/react-native": "^7.2.0",
"babel-jest": "26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "^17.0.1"
},
"transform": {
"^.+\\.[t|j]sx?$": "babel-jest"
}
}
```
jest.config.js:
```const { defaults } = require('jest-config');
module.exports = {
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|js?|tsx?|ts?)$",
transform: {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.mjs$": "babel-jest",
},
testPathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/node_modules/"],
moduleFileExtensions: ["js", "jsx", "mjs"]
}```
Any idea how to solve this error?
I'm facing another issue which is :
SyntaxError: Cannot use import statement outside a module
3 | */
4 |
> 5 | import 'react-native';
| ^
6 | import React from 'react';
7 | import App from '../App';
8 |
when testing App-test.js
Any solution?

How can I create two different entry points for devServer and for production in webpack.config file?

I have a npm accessible-date-picker package that is a React component. It is setup using webpack. I would like to have two entry points: one for the production environment that builds from the demo folder and one for the production environment. The idea is to make it possible to work with an example code in the Demo folder for improvements and when everything is done, build and publish as a npm package.
I can't seem to get the correct syntax down to make two entry points work. Either I get a production ready version that fails when development is run or I get a production ready version.
Here is the folder structure for the project:
|dist
|demo
||index.tsx
|src
| | components
| | container
| | | DatePicker.tsx
Here is webpack.config file that works like a charm for production but can't get development server working. I am not sure how to add a second entry point for the devServer:
entry: "./src/container/DatePicker.tsx",
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, './dist'),
compress: true,
port: 4000,
},
resolve: {
alias: {
'react': path.resolve(__dirname, './node_modules/react'),
'react-dom': path.resolve(__dirname, './node_modules/react-dom'),
},
extensions: [".tsx", ".ts", ".js", ".css", ".scss"],
},
externals: {
react: {
commonjs: "react",
commonjs2: "react",
amd: "React",
root: "React"
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "ReactDOM",
root: "ReactDOM"
}
},
output: {
path: path.join(__dirname, './dist'),
filename: 'accessible-datepicker.js',
libraryTarget: 'umd',
publicPath: '/dist/',
umdNamedDefine: true
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"#babel/preset-env",
"#babel/preset-react",
"#babel/preset-typescript",
],
},
},
},
{
test: /\.css$/i,
use: [
"style-loader",
"#teamsupercell/typings-for-css-modules-loader",
{
loader: "css-loader",
options: { modules: true },
},
],
},
],
}
};
Last but not least the package.json:
"scripts": {
"start": "webpack serve",
"build": "webpack --mode production",
"prepublish": "rm -rf ./dist && npm run build",
"test": "jest"
},
"dependencies": {
"moment": "^2.29.1"
},
"peerDependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"#babel/core": "^7.12.7",
"#babel/plugin-transform-runtime": "^7.12.1",
"#babel/preset-env": "^7.12.7",
"#babel/preset-react": "^7.12.7",
"#babel/preset-typescript": "^7.12.7",
"#babel/runtime": "^7.12.5",
"#teamsupercell/typings-for-css-modules-loader": "^2.4.0",
"#types/fork-ts-checker-webpack-plugin": "^0.4.5",
"#types/jest": "^26.0.15",
"#types/react": "^17.0.0",
"#types/react-dom": "^17.0.0",
"#types/webpack": "^4.41.25",
"#types/webpack-dev-server": "^3.11.1",
"#typescript-eslint/eslint-plugin": "^4.8.1",
"#typescript-eslint/parser": "^4.8.1",
"#wojtekmaj/enzyme-adapter-react-17": "^0.4.1",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.1",
"css-loader": "^5.0.1",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.1",
"eslint": "^7.14.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"fork-ts-checker-webpack-plugin": "^6.0.3",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.6.3",
"node-sass": "^5.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"sass-loader": "^10.1.1",
"style-loader": "^2.0.0",
"ts-jest": "^26.4.4",
"ts-node": "^9.0.0",
"typescript": "^4.1.2",
"webpack": "^5.6.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
}
}
If someone could point out how to write a second entry point that would work with a development server would be of great help.

.eslintrc.js file being ignored with create react app and craco

This has been working great for the last couple of years, but we just upgraded a slew of libraries and now eslint, when we run our app, is not referring to our eslintrc file. It's throwing errors for rules that we have either disabled or set to warning. I can type junk into the eslintrc file and nothing errors on build.
The ESLint extension in VSCode does recognize it and running eslint CLI works as expected. When running npm run start or npm run deploy-build, it seems to ignore the eslintrc file.
.eslintrc.js removed many rules for brevity
module.exports = {
"env": {
"browser": true,
"jest": true
},
"extends": "airbnb",
"globals": {
"_satellite": true
},
"parser": "babel-eslint",
"rules": {
"comma-dangle": 0,
"eol-last": 0,
...
"jsx-a11y/anchor-is-valid": [
2,
{
"components": [
"Link"
],
"specialLink": [
"to"
]
}
],
...
"react/jsx-curly-newline": 0, // this is one rule that I'm specifically chasing
...
},
"settings": {
"import/resolver": {
"node": {
"paths": [
"src"
]
}
}
}
}
craco-config.js
const path = require('path');
const { ESLINT_MODES } = require('#craco/craco');
const StyleLintPlugin = require('stylelint-webpack-plugin');
module.exports = {
jest: {
configure: {
setupFiles: [
'jest-localstorage-mock',
'<rootDir>/jest/global_mocks.js',
'<rootDir>/jest/global_variables.js'
],
testResultsProcessor: 'jest-sonar-reporter',
snapshotSerializers: [
'enzyme-to-json/serializer'
],
collectCoverageFrom: [
'src/**/*.js',
'!src/registerServiceWorker.js',
'!src/**/*.stories.js',
'!src/**/*.styles.js'
],
coverageThreshold: {
global: {
branches: 60,
functions: 70,
lines: 80,
statements: 1
}
},
clearMocks: true
}
},
eslint: {
mode: ESLINT_MODES.file
},
webpack: {
plugins: [
new StyleLintPlugin({
configBasedir: __dirname,
context: path.resolve(__dirname, 'src'),
files: ['**/*.scss']
})
]
}
};
local environment
EXTEND_ESLINT=true
REACT_APP_ENV=local
...
package.json
{
"name": "search",
"version": "1.0.0",
"private": true,
"dependencies": {
"#datadog/browser-rum": "^1.12.8",
"#okta/okta-react": "^3.0.4",
"axios": "^0.18.1",
"connected-react-router": "^6.7.0",
"core-js": "^3.6.5",
"debounce": "^1.2.0",
"eslint-plugin-react-hooks": "^4.1.0",
"fast-text-encoding": "^1.0.2",
"focus-within-polyfill": "^5.0.4",
"history": "^4.10.0",
"jshashes": "^1.0.7",
"lodash.groupby": "^4.6.0",
"lodash.sortby": "^4.7.0",
"moment": "^2.24.0",
"moment-timezone": "^0.5.28",
"prop-types": "^15.6.2",
"qs": "^6.5.2",
"react": "^16.13.0",
"react-app-polyfill": "^1.0.6",
"react-click-outside": "^3.0.1",
"react-cursor-position": "^3.0.3",
"react-dom": "^16.13.0",
"react-easy-swipe": "0.0.17",
"react-flexbox-grid": "^2.1.2",
"react-html-parser": "^2.0.2",
"react-inlinesvg": "^1.1.5",
"react-lazyload": "^2.6.2",
"react-number-format": "^4.0.5",
"react-redux": "^7.2.0",
"react-router": "^5.1.0",
"react-router-dom": "^5.1.0",
"react-scripts": "^3.4.1",
"react-slick": "^0.23.1",
"react-sticky-el": "^1.0.20",
"react-toastify": "^4.2.0",
"react-transition-group": "^4.4.0",
"reactjs-popup": "^1.5.0",
"redux": "^4.0.0",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"rxjs": "^6.5.5",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.83.0",
"slick-carousel": "^1.8.1",
"smoothscroll-polyfill": "^0.4.3",
"styled-components": "^5.1.1",
"use-clipboard-copy": "^0.1.1",
"uuid": "^7.0.2"
},
"devDependencies": {
"#craco/craco": "^5.6.4",
"#storybook/addon-actions": "^5.0.5",
"#storybook/addon-knobs": "^5.0.6",
"#storybook/addon-links": "^5.0.5",
"#storybook/addons": "^5.0.5",
"#storybook/react": "^5.0.5",
"#testing-library/react": "^10.4.7",
"cross-env": "^7.0.2",
"env-cmd": "^10.1.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"enzyme-to-json": "^3.5.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.6",
"jest-environment-jsdom": "^24.9.0",
"jest-environment-node": "^24.9.0",
"jest-localstorage-mock": "^2.4.0",
"jest-sonar-reporter": "^2.0.0",
"jest-styled-components": "^7.0.2",
"libxmljs": "^0.19.7",
"node-sass-chokidar": "^1.5.0",
"npm-link-shared": "^0.5.6",
"redux-mock-store": "^1.5.3",
"stylelint": "^9.10.1",
"stylelint-config-sass-guidelines": "^5.3.0",
"stylelint-webpack-plugin": "^0.10.5"
},
"scripts": {
"localxf": "cross-env NODE_PATH=src env-cmd -f ./env/localxf craco start",
"test": "cross-env NODE_PATH=src craco test --env=jsdom",
"test:debug": "cross-env NODE_PATH=src craco test --runInBand --no-cache --env=jsdom",
"storybook": "cross-env NODE_PATH=src env-cmd -f ./env/local start-storybook -p 6006",
"build-storybook": "build-storybook",
"deploy-build": "cross-env NODE_PATH=src env-cmd -f ./env/deploy-build craco build",
"start": "cross-env NODE_PATH=src env-cmd -f ./env/local craco start --no-cache"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"ie 11",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}
}
I suspect there's a library above I have to update but I'm not sure what else to update!
This seems to be a viable workaround:
eslint: {
mode: ESLINT_MODES.extends,
configure: () => {
// Workaround for broken ESLINT_MODES.file mode
return require('./.eslintrc')
}
},

Webpack GZip Compression Creating many bundles/.gz files instead of 1 entire bundle?

I'm playing around with gzip compression for building out my react project (It's a full stack application) when I run the build script with npm I get no errors but in the process it spits me back around 10 bundles with 10 .gz file extensions instead of one and I'm not sure why?
Here is my code:
Production Webpack
const webpack = require("webpack");
const path = require("path");
const CompressionPlugin = require("compression-webpack-plugin");
module.exports = {
entry: ["babel-polyfill", __dirname + "/src/index.js"],
output: {
path: __dirname + "/public",
filename: "bundle.js",
publicPath: "/"
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
query: {
presets: ["react", "env", "stage-0"]
}
}
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{ loader: "sass-loader" }
]
}
]
},
plugins: [
new CompressionPlugin({
filename: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
minRatio: 0.8,
threshold: 10240
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
})
]
};
NPM Build Script
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"client": "webpack-dev-server --port 3312 --progress --color --profile --config webpack.development.config.js --mode development --hot",
"clean": "rm -rf build public/bundle.js",
"server": "nodemon server/main.js",
"sass": "node-sass -w public/assets/scss -o public/assets/css/ --recursive",
"dev": "concurrently \"npm run server\" \"npm run sass\" \"npm run client\"",
"prod": "npm run clean && webpack --config webpack.production.config.js --mode production --progress --colors --profile"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.373.0",
"base-64": "^0.1.0",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"cors": "^2.8.5",
"data-tip": "0.0.52",
"express": "^4.16.4",
"file-type": "^10.6.0",
"jquery": "^3.3.1",
"moment": "^2.22.2",
"mysql": "^2.16.0",
"nodemailer": "^4.7.0",
"nodemailer-juice": "^1.0.1",
"paypal-rest-sdk": "^1.8.1",
"react": "^16.6.3",
"react-bootstrap": "^0.32.4",
"react-ckeditor-component": "^1.1.0",
"react-confirm-alert": "^2.0.7",
"react-dom": "^16.6.3",
"react-js-pagination": "^3.0.2",
"react-loadable": "^5.5.0",
"react-router-dom": "^4.3.1",
"react-s3-uploader": "^4.8.0",
"read-chunk": "^3.0.0",
"sha256": "^0.2.0"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.0.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"browser-sync": "^2.26.3",
"browser-sync-webpack-plugin": "^2.2.2",
"compression-webpack-plugin": "^2.0.0",
"concurrently": "^4.1.0",
"css-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"node-sass": "^4.10.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"webpack": "^4.27.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
}
}
Screenshot of the output:
This is because you are using Webpack 4, and it comes with automatic code-splitting. You can read how to configure it here:
https://webpack.js.org/guides/code-splitting/