StorybookJS: Accessing non-existent addons channel - reactjs

I am currently trying to add the #storybook/addon-console to Storybook.
After running npm install #storybook/addon-console #storybook/addon-actions --save-dev, I get this error when I try to run npm run storybook:
Error: Accessing non-existent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel
at AddonStore.getChannel (/Users/mitchell/Documents/GitHub/TapTapesWeb/node_modules/#storybook/addons/dist/cjs/index.js:53:13)
I tried to add this to my config.js file as per that link, to no avail:
import addons, { mockChannel } from '#storybook/addons';
addons.setChannel(mockChannel());
This is my Storybook main.js file:
module.exports = {
stories: ['../components/**/*.stories.#(js|jsx|ts|tsx)'],
addons: [
'#storybook/addon-links',
'#storybook/addon-essentials',
'storybook-addon-material-ui',
'#storybook/addon-postcss',
'#storybook/addon-console',
'#storybook/addon-actions'
],
reactOptions: {
fastRefresh: true
}
};
Here is my Storybook config.js file:
import theme, { muiTheme } from '../constants/theme';
import React from 'react';
import { MuiThemeProvider } from '#material-ui/core/styles';
import { ThemeProvider } from 'styled-components';
import CssBaseline from '#material-ui/core/CssBaseline';
export const decorators = [
(Story) => (
<ThemeProvider theme={theme}>
<MuiThemeProvider theme={muiTheme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Story />
</MuiThemeProvider>
</ThemeProvider>
)
];
Here is my package.json:
{
"name": "TapTapesWeb",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "cross-env NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"start": "next start",
"test": "jest --passWithNoTests",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
"postinstall": "husky install",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.34",
"#fortawesome/free-brands-svg-icons": "^5.15.2",
"#fortawesome/free-regular-svg-icons": "^5.15.2",
"#fortawesome/free-solid-svg-icons": "^5.15.2",
"#fortawesome/react-fontawesome": "^0.1.14",
"#material-ui/core": "^4.11.3",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.57",
"#reduxjs/toolkit": "^1.5.0",
"axios": "^0.21.1",
"cross-env": "^7.0.3",
"lodash": "^4.17.21",
"next": "10.0.7",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-horizontal-scrolling-menu": "^0.7.10",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"styled-components": "^5.2.1"
},
"devDependencies": {
"#babel/core": "^7.13.1",
"#storybook/addon-actions": "^6.2.0-beta.5",
"#storybook/addon-console": "^1.2.3",
"#storybook/addon-essentials": "^6.2.0-beta.5",
"#storybook/addon-links": "^6.2.0-beta.5",
"#storybook/addon-postcss": "^2.0.0",
"#storybook/addon-viewport": "^6.2.0-beta.5",
"#storybook/addons": "^6.2.0-beta.5",
"#storybook/react": "^6.2.0-beta.5",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"babel-plugin-styled-components": "^1.12.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"husky": "^5.1.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"storybook-addon-material-ui": "^0.9.0-alpha.24",
"storybook-addon-state": "^1.0.3"
}
}

Related

Is there a chrome-dev-tool to diagnose what is being rendered by React.js?

So I just updated from React 16 -> 18.13.0
My code was all working, but after this update, apart from a few "import" errors which I have fixed, now vs code is not posting anything to my browser. The build is compiling with no errors, a new chrome tab is being opened and there are no errors on either console. I'm guessing this may be due to some version incompatibility, but npm doesn't flag anything.
App.js
import React, {Component} from 'react';
import JSONData from './data/data.json';
import './css/style.css';
import General from './components/general/general.js';
import Campaign from "./pages/campaign/campaign.js";
import Services from "./pages/services/services.js";
import Contact from './pages/contact/contact.js';
import {BrowserRouter as Router, Route, Routes} from "react-router-dom";
export class App extends Component {
state = {
landingPageDats: {},
}
getlandingPageData() {
this.setState({landingPageData : JSONData})
}
componentDidMount() {
this.getlandingPageData();
}
render() {
return(
<Router>
<Routes>
<Route path="/" element={<General/>}/>
<Route path="/campaign" element={<Campaign/>}/>
<Route path="/services" element={<Services/>}/>
<Route path="/contacts" element={<Contact/>}/>
</Routes>
</Router>
)
}
}
export default App;
Package.json
{
"name": "trustmotores",
"version": "1.0.0",
"private": true,
"homepage": "https://trustmotores.com",
"proxy": "http://trustmotores.com",
"type": "module",
"jsx": "react-jsx",
"dependencies": {
"#coreui/coreui": "^4.2.2",
"#coreui/react": "^4.4.0",
"#emotion/react": "^11.10.4",
"#emotion/styled": "^11.10.4",
"#material-ui/core": "^4.12.4",
"#material-ui/icons": "^4.11.3",
"#mui/icons-material": "^5.10.9",
"#mui/material": "^5.10.10",
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/user-event": "^12.1.10",
"axios": "^0.21.4",
"babel": "^6.23.0",
"body-parser": "^1.19.0",
"concurrently": "^6.2.1",
"contentful": "^9.2.11",
"cors": "^2.8.5",
"express": "^4.17.1",
"node-pre-gyp": "^0.17.0",
"node-sass": "^8.0.0",
"nodemailer": "^6.6.3",
"pure-react-carousel": "^1.28.1",
"react": "^18.2.0",
"react-awesome-slider": "^4.1.0",
"react-calendar": "^3.9.0",
"react-dom": "^18.2.0",
"react-icons": "^4.2.0",
"react-responsive-carousel": "^3.2.23",
"react-router": "^5.3.1",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"react-select": "^5.6.0",
"react-slick": "^0.28.1",
"react-swipe": "^6.0.4",
"sass": "^1.56.0",
"slick-carousel": "^1.8.1",
"swipe-js-iso": "^2.1.5",
"update": "^0.4.2",
"web-vitals": "^1.0.1",
"yarn": "^1.22.18"
},
"jest": {
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/styleMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"verbose": "true"
}
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject",
"client": "npm start ",
"server": "nodemon server.js",
"dev": "concurrently \"npm run client\" \"npm run server\" "
},
"eslintConfig": {
"extends": [
"react-app"
]
},
"devDependencies": {
"#babel/core": "^7.15.5",
"#babel/preset-env": "^7.15.6",
"#babel/preset-react": "^7.14.5",
"#react-ui-org/react-ui": "^0.49.0",
"#testing-library/react": "^12.0.0",
"babel-jest": "^27.5.1",
"enzyme": "^3.11.0",
"eslint": "^7.11.0",
"jest": "^27.2.0",
"jest-dom": "^4.0.0",
"jsdom": "20.0.2",
"jsdom-global": "3.0.2",
"nodemon": "^2.0.12",
"react-test-renderer": "^17.0.2",
"swiper": "^8.4.4"
},
"description": "A Trust Motores é uma comercializadora de produtos Auto a nivel nacional.",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/tomascdmota/trustmotores.git"
},
"author": "Tomas Mota",
"license": "MIT",
"bugs": {
"url": "https://github.com/tomascdmota/trustmotores/issues"
},
"transform": {
"\\.js$": "<rootDir>/node_modules/babel-jest"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Let me know if you need any more info. Thank you

svgr/webpack Not Working With Webpack 5 and SingleSpa

I been struggling with this for a week, I been reading another Stackoverflow questions and the SVGR/WEBPACK documentation but I'm unable to solve this.
I wanted to upgrade an old react single-spa application but it had a lot of conflicting dependencies so I simply went and created a new one using the Single Spa Playground web application, everything works great but I can't get my SVG'S as React Components with SVGR/WEBPACK.
The error:
webpack.config.js
const webpackMerge = require("webpack-merge").merge;
const singleSpaDefaults = require("webpack-config-single-spa-react-ts");
module.exports = (webpackConfigEnv, argv) => {
const defaultConfig = singleSpaDefaults({
orgName: "testorg",
projectName: "testproj",
webpackConfigEnv,
argv,
});
return webpackMerge(defaultConfig, {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.svg$/,
use: ["#svgr/webpack"],
},
],
},
});
};
How I'm importing the svg
import TestImg from "../../assets/icons/testimage.svg";
How I'm using the SVG
<TestImg />
declarations.d.ts
I'm not entirely sure how does this works but I also removed this and it's the same.
declare module "*.svg" {
const content: React.FC<React.SVGAttributes<SVGElement>>;
export default content;
}
package.json
{
"name": "#testorg/testproj",
"scripts": {
"start": "webpack serve",
"start:standalone": "webpack serve --env standalone",
"build": "concurrently npm:build:*",
"build:webpack": "webpack --mode=production",
"analyze": "webpack --mode=production --env analyze",
"lint": "eslint src --ext js,ts,tsx",
"format": "prettier --write .",
"check-format": "prettier --check .",
"test": "cross-env BABEL_ENV=test jest",
"watch-tests": "cross-env BABEL_ENV=test jest --watch",
"prepare": "husky install",
"coverage": "cross-env BABEL_ENV=test jest --coverage",
"build:types": "tsc"
},
"devDependencies": {
"#babel/core": "^7.15.0",
"#babel/eslint-parser": "^7.15.0",
"#babel/plugin-transform-runtime": "^7.15.0",
"#babel/preset-env": "^7.15.0",
"#babel/preset-react": "^7.14.5",
"#babel/preset-typescript": "^7.15.0",
"#babel/runtime": "^7.15.3",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^12.0.0",
"#types/testing-library__jest-dom": "^5.14.1",
"babel-jest": "^27.0.6",
"concurrently": "^6.2.1",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-ts-react-important-stuff": "^3.0.0",
"eslint-plugin-prettier": "^3.4.1",
"husky": "^7.0.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.0.6",
"jest-cli": "^27.0.6",
"prettier": "^2.3.2",
"pretty-quick": "^3.1.1",
"sass": "^1.56.2",
"sass-loader": "^13.2.0",
"ts-config-single-spa": "^3.0.0",
"typescript": "^4.3.5",
"webpack": "^5.75.0",
"webpack-cli": "^4.8.0",
"webpack-config-single-spa-react": "^4.0.0",
"webpack-config-single-spa-react-ts": "^4.0.0",
"webpack-config-single-spa-ts": "^4.0.0",
"webpack-dev-server": "^4.0.0",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"#datepicker-react/hooks": "^2.8.4",
"#svgr/webpack": "^6.5.1",
"#types/jest": "^27.0.1",
"#types/react": "^17.0.19",
"#types/react-dom": "^17.0.9",
"#types/systemjs": "^6.1.1",
"#types/webpack-env": "^1.16.2",
"date-fns": "^2.29.3",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-datepicker": "^4.8.0",
"react-dom": "^17.0.2",
"react-modal": "^3.16.1",
"react-number-format": "^5.1.2",
"react-toastify": "^6.2.0",
"single-spa": "^5.9.3",
"single-spa-react": "^4.3.1",
"styled-components": "^5.3.6"
},
"types": "dist/testorg-testproj.d.ts"
}
The only way it works
The only way I got it working is uninstalling #svgr/webpack and using my imported svg inside of an img tag, as a source.
<img src={TestImg} alt='' width='200' height='200' />
But is not what I want, I need to be able modify the svg fill by props and that's why I need it as a React Component.
Also, I have a LOT of icons and logos in this project, so manually creating a React Component in my project for each image/icon it's not the solution I'm looking for.
Additional information 1
I put a console log for the TestImg and it shows an url, clearly it's not importing it as a component
If I go to the url this is what it shows:
Additional information 2
import { ReactComponent as TestImg } from "../../assets/icons/testimage.svg"
Doesn't work either, it says:
Can't import the named export 'ReactComponent' (imported as 'TestImg') from default-exporting module (only default export is available)

export 'useEffect' (imported as 'useEffect') was not found in 'react' (module has no exports)

I am receiving errors of:
It seems to be errors related with redux and react redux:
I also have a warning of:
Attempted import error: 'useMemo' is not exported from 'react' (imported as 'useMemo').
LOG from webpack.FileSystemInfo
<w> Managed item C:\Users\Bernadette Kotelo\Documents\Gahn Eden\frontend\node_modules\react-redux\node_modules\#babel\runtime isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)
+ 11 hidden lines
Here's my package.json inside my react redux folder in node_modules:
{
"name": "react-redux",
"version": "8.0.2",
"description": "Official React bindings for Redux",
"keywords": [
"react",
"reactjs",
"redux"
],
"license": "MIT",
"author": "Dan Abramov <dan.abramov#me.com> (https://github.com/gaearon)",
"homepage": "https://github.com/reduxjs/react-redux",
"repository": "github:reduxjs/react-redux",
"bugs": "https://github.com/reduxjs/react-redux/issues",
"main": "./lib/index.js",
"types": "./es/index.d.ts",
"unpkg": "dist/react-redux.js",
"module": "es/index.js",
"files": [
"dist",
"lib",
"src",
"es"
],
"scripts": {
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --extensions \".js,.ts,.tsx\" --out-dir lib",
"build:es": "babel src --extensions \".js,.ts,.tsx\" --out-dir es",
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/react-redux.js",
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/react-redux.min.js",
"build:types": "tsc",
"build": "yarn build:types && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:umd:min",
"clean": "rimraf lib dist es coverage",
"api-types": "api-extractor run --local",
"format": "prettier --write \"{src,test}/**/*.{js,ts,tsx}\" \"docs/**/*.md\"",
"lint": "eslint src --ext ts,tsx,js test/utils test/components test/hooks",
"prepare": "yarn clean && yarn build",
"pretest": "yarn lint",
"test": "jest",
"type-tests": "yarn tsc -p test/typetests/tsconfig.json",
"coverage": "codecov"
},
"peerDependencies": {
"#types/react": "^16.8 || ^17.0 || ^18.0",
"#types/react-dom": "^16.8 || ^17.0 || ^18.0",
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0",
"react-native": ">=0.59",
"redux": "^4"
},
"peerDependenciesMeta": {
"#types/react": {
"optional": true
},
"#types/react-dom": {
"optional": true
},
"react-dom": {
"optional": true
},
"react-native": {
"optional": true
},
"redux": {
"optional": true
}
},
"dependencies": {
"#babel/runtime": "^7.12.1",
"#types/hoist-non-react-statics": "^3.3.1",
"#types/use-sync-external-store": "^0.0.3",
"hoist-non-react-statics": "^3.3.2",
"react-is": "^18.0.0",
"use-sync-external-store": "^1.0.0"
},
"devDependencies": {
"#babel/cli": "^7.12.1",
"#babel/core": "^7.12.3",
"#babel/plugin-proposal-decorators": "^7.12.1",
"#babel/plugin-proposal-object-rest-spread": "^7.12.1",
"#babel/plugin-transform-react-display-name": "^7.12.1",
"#babel/plugin-transform-react-jsx": "^7.12.1",
"#babel/plugin-transform-runtime": "^7.12.1",
"#babel/preset-env": "^7.12.1",
"#babel/preset-typescript": "^7.14.5",
"#microsoft/api-extractor": "^7.18.1",
"#reduxjs/toolkit": "^1.6.1",
"#rollup/plugin-babel": "^5.2.1",
"#rollup/plugin-commonjs": "^15.1.0",
"#rollup/plugin-node-resolve": "^9.0.0",
"#rollup/plugin-replace": "^2.3.3",
"#testing-library/jest-dom": "^5.11.5",
"#testing-library/jest-native": "^3.4.3",
"#testing-library/react": "13.0.0",
"#testing-library/react-12": "npm:#testing-library/react#^12",
"#testing-library/react-hooks": "^3.4.2",
"#testing-library/react-native": "^7.1.0",
"#types/object-assign": "^4.0.30",
"#types/react": "^18",
"#types/react-dom": "^18",
"#types/react-is": "^17",
"#types/react-native": "^0.67.4",
"#typescript-eslint/eslint-plugin": "^4.28.0",
"#typescript-eslint/parser": "^4.28.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.1",
"codecov": "^3.8.0",
"cross-env": "^7.0.2",
"eslint": "^7.12.0",
"eslint-config-prettier": "^6.14.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.5",
"glob": "^7.1.6",
"jest": "^26.6.1",
"prettier": "^2.1.2",
"react": "18.0.0",
"react-17": "npm:react#^17",
"react-dom": "18.0.0",
"react-dom-17": "npm:react-dom#^17",
"react-native": "^0.64.1",
"react-test-renderer": "18.0.0",
"react-test-renderer-17": "npm:react-test-renderer#^17",
"redux": "^4.0.5",
"rimraf": "^3.0.2",
"rollup": "^2.32.1",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "26.5.6",
"typescript": "^4.3.4"
}
}
And heres is my main app package.json:
{
"name": "frontend",
"proxy": "http://localhost:5000/",
"version": "0.1.0",
"private": true,
"dependencies": {
"#chakra-ui/icons": "^2.0.9",
"#chakra-ui/react": "^2.3.2",
"#chakra-ui/system": "^2.2.9",
"#chakra-ui/theme-tools": "^2.0.11",
"#emotion/cache": "^11.10.3",
"#emotion/react": "^11.10.4",
"#emotion/styled": "^11.10.4",
"#hypertheme-editor/chakra-ui": "^0.2.0-dev.1",
"#mui/icons-material": "^5.10.3",
"#mui/material": "^5.10.5",
"#mui/styled-engine": "^5.10.5",
"#reduxjs/toolkit": "^1.8.5",
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"apexcharts": "^3.35.5",
"axios": "^0.27.2",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"bootstrap": "^5.2.0",
"chart.js": "^3.9.1",
"chroma-js": "^2.4.2",
"framer-motion": "^7.2.1",
"jwt-decode": "^3.1.2",
"primeflex": "^3.2.1",
"primeicons": "^5.0.0",
"primereact": "^8.4.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-apexcharts": "^1.4.0",
"react-bootstrap": "^2.5.0",
"react-calendar": "^3.8.0",
"react-chartjs-2": "^4.3.1",
"react-custom-scrollbars-2": "^4.5.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.2",
"react-github-btn": "^1.4.0",
"react-icons": "^4.4.0",
"react-is": "^18.2.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"react-table": "^7.8.0",
"react-toastify": "^9.0.8",
"react-transition-group": "^4.4.5",
"redux": "^4.2.0",
"redux-persist": "^6.0.0",
"sass": "^1.54.9",
"sass-loader": "^13.0.2",
"stylis": "^4.1.2",
"stylis-plugin-rtl": "^2.0.2",
"swiper": "^8.4.0",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I have tried uninstalling redux and react-redux and installing them again. It failed.
The errors say all my react hooks cannot be imported in react, inside my node_mudules/react-redux folder. Which is confusing because I have react installed.
Please help me. Thanks
I just ran into this issue. I deleted my node_modules folder rm -rf node_modules/ and ran npm i, and the issue was fixed.

React Three Drei can't resolve react-dom/client 17.0.1

three version:^0.140.2
#react-three/fiber version:^8.0.19
#react-three/drei version:^9.11.0
node version:14.18.13
npm (or yarn) version: 1.22.17 (yarn)
react version:17.0.1
react-dom version:17.0.1
Problem description:
Implementing react three drei above my NextJS app getting an error when go to the page which import react three drei, like the following:
./node_modules/#react-three/drei/web/Html.js:3:0 Module not found: Can't resolve 'react-dom/client' Import trace for requested module: ./node_modules/#react-three/drei/index.js ./components/Model3D/ThreeDModel.js ./pages/new.js
Expected:
I go to 'new' page, then I can load 3d model with .glb format from HTML input tag using useGLTF
Relevant Code:
import React from 'react'
import { useGLTF } from '#react-three/drei/core/useGLTF'
import { OrbitControls } from '#react-three/drei'
import { parseImgUrl } from 'utils/common'
const Model1 = ({ threeDUrl }) => {
const loadedGltf = useGLTF(parseImgUrl(threeDUrl), true)
return (
<>
<primitive object={loadedGltf.scene} dispose={null} />
<OrbitControls />
<ambientLight />
</>
)
}
export { Model1 }
Suggested Solution:
At this time, I think root cause of the error is that my react three drei which I used don't supported react#17.0.1. I expected that previous react three drei version support react#17.0.1 then really wonder what specified version that support react#17.0.1 or maybe the error was caused by other things. Thank you for your support, that's always my pleasure.
This is the entire dependencies within package.json
{
"name": "paras-v2-landing",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"dev:testnet": "PORT=8081 dotenv -e .env.testnet next dev",
"dev:mainnet": "PORT=8082 dotenv -e .env.mainnet next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier --write .",
"prettier-check": "prettier --check .",
"prepare": "husky install"
},
"dependencies": {
"#draft-js-plugins/anchor": "^4.1.1",
"#draft-js-plugins/buttons": "^4.0.0",
"#draft-js-plugins/divider": "^4.1.1",
"#draft-js-plugins/editor": "^4.0.0",
"#draft-js-plugins/focus": "^4.1.0",
"#draft-js-plugins/image": "^4.0.0",
"#draft-js-plugins/inline-toolbar": "^4.1.0",
"#draft-js-plugins/linkify": "^4.1.0",
"#draft-js-plugins/static-toolbar": "^4.0.0",
"#draft-js-plugins/video": "^4.1.0",
"#react-three/drei": "^9.11.0",
"#react-three/fiber": "^8.0.19",
"#sentry/nextjs": "^6.12.0",
"#tailwindcss/line-clamp": "^0.3.1",
"axios": "^0.21.0",
"blurhash": "^1.1.3",
"cachios": "^3.0.0",
"capitalize": "^2.0.4",
"cids": "^1.1.5",
"compressorjs": "^1.0.7",
"croppie": "^2.6.5",
"draft-js": "^0.11.7",
"file-type": "^16.5.3",
"generate-avatar": "^1.4.10",
"javascript-time-ago": "^2.3.2",
"js-base64": "^3.5.2",
"js-cookie": "^2.2.1",
"jsbi": "^3.1.4",
"near-api-js": "^0.42.0",
"next": "^12.1.6",
"postcss": "^8.4.12",
"query-string": "^7.0.1",
"react": "^18.1.0",
"react-awesome-animated-number": "^1.0.6",
"react-blurhash": "^0.1.3",
"react-card-flip": "^1.1.5",
"react-content-loader": "^6.0.3",
"react-custom-scrollbars": "^4.2.1",
"react-dom": "^18.1.0",
"react-fast-marquee": "^1.1.3",
"react-google-recaptcha": "^2.1.0",
"react-hamburgers": "^1.0.0",
"react-hook-form": "^6.10.0",
"react-horizontal-scrolling-menu": "^2.7.0",
"react-infinite-scroll-component": "^5.1.0",
"react-intl": "^5.9.2",
"react-linkify": "^1.0.0-alpha",
"react-responsive-carousel": "^3.2.23",
"react-share": "^4.3.1",
"react-slick": "^0.28.1",
"react-tooltip": "^4.2.17",
"recharts": "^2.1.9",
"slick-carousel": "^1.8.1",
"swr": "^1.2.2",
"three": "^0.140.2",
"three-stdlib": "^2.10.1",
"uuid": "^8.3.2",
"zustand": "^3.1.3"
},
"devDependencies": {
"#next/bundle-analyzer": "^12.1.4",
"autoprefixer": "^10.4.4",
"dotenv-cli": "^4.1.1",
"eslint": "^7.30.0",
"eslint-config-next": "^11.0.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.0",
"lint-staged": "^11.1.2",
"postcss-import": "^13.0.0",
"postcss-preset-env": "^6.7.0",
"prettier": "2.4.1",
"pretty-quick": "^3.1.2",
"tailwindcss": "^3.0.23"
},
"license": "GPL-3.0",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.{html,css,less,ejs}": [
"git add"
]
}
}

React-intl - How to use a default Locale

This could be a very easy question, however I've not been able to find the answer for it anywhere.
How do I use a default locale with react-intl? Specifying a default message every time gets really messy. The way that I'm doing it at the moment doesn't seem to pick up the default message when the browser uses a locale that doesn't have a translation.
How I'm using it at the moment:
import React from 'react'
import { Route } from 'react-router-dom'
import { IntlProvider } from 'react-intl'
import { Provider } from 'react-redux'
import { MuiThemeProvider, CssBaseline } from '#material-ui/core'
// import translations
import da_translations from './translations/da.json'
import de_translations from './translations/de.json'
import el_translations from './translations/el.json'
import en_translations from './translations/en.json'
import defaultTheme from './themes/default'
import {
QueryParamProvider,
ExtendedStringifyOptions,
transformSearchStringJsonSafe,
} from 'use-query-params'
import configureStore from './redux/configure-store'
import { Routes } from './routes'
const store = configureStore()
const App = (): JSX.Element => {
const state = { locale: navigator.language.slice(0, 2) }
const messages: { [index: string]: any } = {
da: da_translations,
de: de_translations,
el: el_translations,
en: en_translations,
}
const queryStringifyOptions: ExtendedStringifyOptions = {
transformSearchString: transformSearchStringJsonSafe,
}
return (
<Provider store={store}>
<IntlProvider
defaultLocale={'en'}
locale={state.locale}
messages={messages[state.locale]}
>
<QueryParamProvider
ReactRouterRoute={Route}
stringifyOptions={queryStringifyOptions}
>
<MuiThemeProvider theme={defaultTheme}>
<CssBaseline />
<Routes />
</MuiThemeProvider>
</QueryParamProvider>
</IntlProvider>
</Provider>
)
}
export default App
edit:
package.json
{
"name": "myproj",
"version": "0.8.47",
"description": "frontend",
"private": false,
"main": "dist/index.js",
"dependencies": {
"#babel/register": "^7.12.1",
"#date-io/date-fns": "^1.3.13",
"#google-cloud/translate": "^6.0.3",
"#material-ui/core": "^4.11.1",
"#material-ui/icons": "4.2.1",
"#material-ui/lab": "^4.0.0-alpha.56",
"#material-ui/pickers": "^3.2.10",
"#types/axios": "^0.14.0",
"#types/history": "^4.7.3",
"#types/jest": "^24.9.1",
"#types/lodash": "^4.14.158",
"#types/node": "^12.12.7",
"#types/react": "^16.9.11",
"#types/react-dom": "^16.9.4",
"#types/react-html-parser": "^2.0.1",
"#types/react-intl": "^3.0.0",
"#types/react-redux": "^7.1.9",
"#types/react-resizable": "^1.7.2",
"#types/react-router-dom": "^5.1.2",
"#types/reselect": "^2.2.0",
"#types/seamless-immutable": "^7.1.13",
"accept-language": "^3.0.18",
"ag-grid-community": "^23.1.1",
"ag-grid-react": "^23.1.1",
"axios": "^0.19.1",
"chai": "^4.2.0",
"chartist": "0.10.1",
"classnames": "^2.2.6",
"clsx": "^1.1.0",
"date-fns": "^2.9.0",
"flexsearch": "^0.6.32",
"fs-extra": "^9.0.1",
"history": "4.9.0",
"immutable": "^4.0.0-rc.12",
"js-yaml": "^3.14.0",
"lodash": "^4.17.19",
"log4js": "^6.3.0",
"loglevel": "^1.6.6",
"minimist": "^1.2.5",
"perfect-scrollbar": "1.4.0",
"prop-types": "15.7.2",
"qs": "^6.9.4",
"query-string": "^6.13.1",
"react": "^16.12.0",
"react-chartist": "0.13.3",
"react-dom": "^16.12.0",
"react-google-maps": "9.4.5",
"react-html-parser": "^2.0.2",
"react-intl": "^3.11.0",
"react-redux": "^7.2.1",
"react-resizable": "^1.10.1",
"react-router-dom": "^5.1.2",
"react-scripts": "4.0.0",
"react-swipeable-views": "0.13.3",
"redux": "^4.0.5",
"redux-observable": "^1.2.0",
"reselect": "^4.0.0",
"seamless-immutable": "^7.1.4",
"use-query-params": "^1.1.6"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env jest-environment-jsdom-sixteen --verbose",
"eject": "react-scripts eject",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
"lint:check": "eslint . --ext=js,jsx; exit 0",
"lint:fix": "eslint . --ext=js,jsx --fix; exit 0",
"build-package-css": "cp src/assets/css/material-dashboard-react.css dist/material-dashboard-react.css",
"build-package": "npm run build-package-css && babel src --out-dir dist"
},
"keywords": [],
"author": "tb",
"license": "MIT",
"homepage": "./",
"optionalDependencies": {
"#types/googlemaps": "3.37.3",
"#types/markerclustererplus": "2.1.33",
"ajv": "6.10.2"
},
"devDependencies": {
"#testing-library/dom": "^7.24.2",
"#testing-library/jest-dom": "^5.11.1",
"#testing-library/react": "^10.4.7",
"#testing-library/user-event": "^12.1.4",
"#types/chai": "^4.2.13",
"#types/classnames": "^2.2.10",
"#types/enzyme": "^3.10.5",
"#types/enzyme-adapter-react-16": "^1.0.6",
"#types/gulp": "^4.0.7",
"#types/jsdom": "^16.2.2",
"#typescript-eslint/eslint-plugin": "^4.7.0",
"#typescript-eslint/parser": "^4.7.0",
"axios-mock-adapter": "^1.18.2",
"cross-env": "^5.1.4",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint-config-prettier": "6.0.0",
"eslint-plugin-prettier": "3.1.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"gulp": "^4.0.2",
"gulp-append-prepend": "1.0.8",
"gulp-filter": "^6.0.0",
"gulp-prettier": "^3.0.0",
"husky": "^4.3.0",
"jest-environment-jsdom-sixteen": "^1.0.3",
"jsdom": "^16.2.2",
"prettier": "^2.1.2",
"pretty-quick": "^3.1.0",
"react-intl-translations-manager": "^5.0.3",
"ts-node": "^9.0.0",
"typescript": "^3.9.7"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": []
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!(#ui5|lit-html)).*\\.js$"
]
}
}

Resources