Errors when using storybook with React and Chakra UI - reactjs

I'm using React (17.0.2), Chakra UI and Storybook (6.5.15) to create a component library. I don't use create-react-app because I don't really need to run it as an app. However, I can't get around the errors related to the core node modules that I receive like can't resolve module 'fs'. I have tried to add custom configuration to main.js for Storybook's webpack v5 so that it will ignore the node core modules like this:
webpackFinal: (config) => {
config.resolve.fallback.fs = false;
config.resolve.fallback.module = false;
config.resolve.fallback.os = false;
return config;
},
When I try to show the story for the component I receive the following error:
TypeError: fs[fsStatType] is not a function
at isTypeSync (http://localhost:6006/vendors-node_modules_chakra-ui_layout_dist_chakra-ui-layout_esm_js-node_modules_chakra-ui_spi-d8af64.iframe.bundle.js:116363:24)
at getDirectorySync (http://localhost:6006/vendors-node_modules_chakra-ui_layout_dist_chakra-ui-layout_esm_js-node_modules_chakra-ui_spi-d8af64.iframe.bundle.js:82082:61)
at ExplorerSync.searchSync (http://localhost:6006/vendors-node_modules_chakra-ui_layout_dist_chakra-ui-layout_esm_js-node_modules_chakra-ui_spi-d8af64.iframe.bundle.js:81910:63)
Below you'll find a list of the dev dependencies from my package.json.
"devDependencies": {
"#babel/cli": "^7.20.7",
"#babel/core": "^7.20.12",
"#babel/preset-env": "^7.20.2",
"#babel/preset-react": "^7.18.6",
"#chakra-ui/react": "^1.7.1",
"#chakra-ui/storybook-addon": "^4.0.16",
"#emotion/react": "^11.1.5",
"#emotion/styled": "^11.1.5",
"#rollup/plugin-babel": "^6.0.3",
"#rollup/plugin-commonjs": "^24.0.0",
"#rollup/plugin-node-resolve": "^15.0.1",
"#rollup/plugin-typescript": "^10.0.1",
"#storybook/addon-actions": "^6.5.15",
"#storybook/addon-essentials": "^6.5.15",
"#storybook/addon-interactions": "^6.5.15",
"#storybook/addon-links": "^6.5.15",
"#storybook/builder-webpack5": "^6.5.15",
"#storybook/manager-webpack5": "^6.5.15",
"#storybook/react": "^6.5.15",
"#storybook/testing-library": "0.0.13",
"#types/react": "^18.0.26",
"babel-loader": "^8.3.0",
"base64-arraybuffer": "^1.0.2",
"cross-fetch": "^3.1.5",
"crypto": "^1.0.1",
"framer-motion": "^6.5.0",
"jest-fetch-mock": "^3.0.3",
"js-cookie": "^3.0.1",
"jwt-decode": "^3.1.2",
"nanoid": "^4.0.0",
"njwt": "^1.2.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"npm-run-all": "^4.1.5",
"randomstring": "^1.2.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rollup": "^3.9.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^5.1.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"tslib": "^2.4.1",
"typescript": "^4.9.4",
"webpack": "^5.75.0"},
Does anyone have an idea on how to solve this issue?
I have tried to add the NodePolyfillPlugin plugin to webpack but I was still receiving errors related to fs, likely because it doesn't have a fallback for it and adding aliases with the modules to resolve it to node modules but I wasn't able to find an npm package for 'fs'. It seems deprecated?

Related

Unable to import private NPM package from Storybook distribution after update to Webpack 5

We have a component library that we build and test using Storybook (6.5.8) which pushes to chromatic and to a private NPM repository. We then import the npm package into our various projects.
This has all been working great.
Recently with a new Open SSL vulnerability coming up we did some security auditing and implemented a dependabot to make sure all our packages were updated to patch the vulnerabilities.
So we updated our configs to work with webpack 5 and everything seemed to be running smoothly with our github actions and the storybook design system was working fine. The issue now is when we import the npm package into our projects we get a blank page as it now can't seem to render anything from the npm package at all.
The console shows all the errors for the components as
Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
We are getting no errors in our release action or when running the storybook design system.
Current dependencies:
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^6.1.1",
"#fortawesome/free-solid-svg-icons": "^6.1.1",
"#fortawesome/react-fontawesome": "^0.1.18",
"#pix4d/three-potree-loader": "^0.0.8",
"#storybook/client-api": "^6.5.8",
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"#tippyjs/react": "^4.2.6",
"chart.js": "^3.9.1",
"chartjs-adapter-moment": "^1.0.0",
"chartjs-plugin-zoom": "^1.2.1",
"echarts": "^5.3.3",
"echarts-for-react": "^3.0.2",
"esri-loader": "^3.6.0",
"esri-loader-hooks": "^0.4.0",
"formik": "^2.2.9",
"glob": "^8.0.3",
"lodash.orderby": "^4.6.0",
"moment": "^2.29.4",
"polished": "^4.1.1",
"prettier": "^2.6.2",
"proj4": "^2.8.0",
"react": "^17.0.1",
"react-chartjs-2": "^4.3.1",
"react-dom": "^17.0.1",
"react-inner-image-zoom": "^3.0.2",
"react-loading-skeleton": "^3.1.0",
"react-moment": "^1.1.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-select": "^5.4.0",
"react-spinners": "^0.13.4",
"sass": "^1.50.1",
"styled-components": "^5.2.1",
"tippy.js": "^6.3.7",
"web-vitals": "^1.0.1",
"yup": "^0.32.11"
},
"devDependencies": {
"#babel/cli": "^7.17.6",
"#storybook/addon-a11y": "^6.5.8",
"#storybook/addon-actions": "^6.5.8",
"#storybook/addon-essentials": "^6.5.8",
"#storybook/addon-interactions": "^6.5.8",
"#storybook/addon-links": "^6.5.8",
"#storybook/builder-webpack5": "^6.5.8",
"#storybook/client-api": "^6.5.8",
"#storybook/jest": "^0.0.10",
"#storybook/manager-webpack5": "^6.5.8",
"#storybook/node-logger": "^6.5.8",
"#storybook/preset-create-react-app": "^4.1.2",
"#storybook/react": "^6.5.8",
"#storybook/testing-library": "^0.0.11",
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"auto": "^10.36.5",
"babel-plugin-styled-components": "^2.0.7",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"chromatic": "^6.5.4",
"copy-webpack-plugin": "^6.4.1",
"cross-env": "^7.0.3",
"html-webpack-plugin": "^4.5.2",
"lodash.orderby": "^4.6.0",
"npm-prepare-dist": "^0.3.0",
"polished": "^4.1.1",
"prettier": "^2.6.2",
"react-scripts": "5.0.1",
"sass-loader": "^9.0.2",
"styled-components": "^5.2.1",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "5",
"webpack-babel-env-deps": "1.5.0",
"webpack-cli": "^4.10.0"
},
Rolled back repository to pre webpack updates and it all worked perfectly. Tried to do updates step by step but as soon as we move to webpack 5 it all breaks. We need to have the updated packages, so we aren't exposed to vulnerabilities, but I also need this to work obviously.
If anyone comes across this, it turns out the issue was with the uglifyjs-webpack-plugin. It is not compatible with webpack5.

Why nx is throwing error when running storybook

I'm trying to run my custom react component library through storybook with nx.
Expected Result
Whenever I run nx run my-lib:storybook command the storybook will open successfuly.
Actual results
After running the command I see the following error:
webpack built preview 90be684218940772f424 in 162ms Error: NormalModuleFactory.beforeResolve (IgnorePlugin) is no longer a waterfall hook, but a bailing hook instead. Do not return the passed object, but modify it instead. Returning false will ignore the request and results in no module created. at .....
Screenshot from nx cloud:
Dependencies of my app
"dependencies": {
"#emotion/react": "11.9.3",
"#emotion/styled": "11.9.3",
"#rollup/plugin-commonjs": "21.1.0",
"#testing-library/jest-dom": "5.15.1",
"axios": "0.24.0",
"core-js": "3.6.5",
"http-proxy-middleware": "2.0.1",
"jszip": "3.7.1",
"msw": "0.36.3",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-slick": "0.28.1",
"react-router-dom": "6.0.2",
"react-canvas-draw": "1.2.1",
"react-lottie-player": "1.4.1",
"react-zoom-pan-pinch": "2.1.3",
"regenerator-runtime": "0.13.7",
"tiny-cookie": "2.3.2",
"tslib": "2.3.0"
},
"devDependencies": {
"#babel/core": "7.16.0",
"#babel/plugin-proposal-private-property-in-object": "7.16.7",
"#babel/preset-env": "7.16.4",
"#babel/preset-react": "7.18.6",
"#babel/preset-typescript": "7.18.6",
"#craco/craco": "6.4.5",
"#emotion/babel-plugin": "11.9.2",
"#nrwl/cli": "14.4.3",
"#nrwl/cypress": "14.4.3",
"#nrwl/eslint-plugin-nx": "14.4.3",
"#nrwl/linter": "14.4.3",
"#nrwl/nx-cloud": "latest",
"#nrwl/react": "14.4.3",
"#nrwl/storybook": "14.4.3",
"#nrwl/web": "14.4.3",
"#nrwl/workspace": "14.4.3",
"#storybook/addon-essentials": "6.5.9",
"#storybook/builder-webpack5": "6.5.9",
"#storybook/core-server": "6.5.9",
"#storybook/manager-webpack5": "6.5.9",
"#storybook/react": "6.5.9",
"#svgr/webpack": "5.4.0",
"#testing-library/react": "11.2.7",
"#testing-library/react-hooks": "7.0.2",
"#testing-library/user-event": "12.8.3",
"#types/jest": "27.4.1",
"#types/node": "17.0.22",
"#types/qs": "6.9.7",
"#types/react": "17.0.37",
"#types/react-canvas-draw": "1.1.1",
"#types/react-dom": "17.0.14",
"#types/react-slick": "0.23.8",
"#typescript-eslint/eslint-plugin": "5.29.0",
"#typescript-eslint/parser": "5.29.0",
"babel-jest": "27.5.1",
"babel-loader": "8.1.0",
"cypress": "9.1.0",
"eslint": "8.15.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "16.1.0",
"eslint-config-prettier": "8.3.0",
"eslint-config-react-app": "7.0.1",
"eslint-plugin-cypress": "2.10.3",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react": "7.30.1",
"husky": "7.0.4",
"jest": "27.5.1",
"jest-mock": "27.5.1",
"jest-watch-typeahead": "2.0.0",
"lint-staged": "12.1.2",
"nx": "14.4.3",
"prettier": "2.6.2",
"react-scripts": "4.0.3",
"react-test-renderer": "17.0.2",
"sass": "1.44.0",
"ts-jest": "27.1.4",
"ts-node": "10.4.0",
"typescript": "4.5.2",
"url-loader": "3.0.0",
"web-vitals": "2.1.4"
},
I think it's something related to webpack versions but it's only a guess.
Thank you for your help.
I found this issue reported on the Storybook GitHub. Can you check if it provides a workaround for the issue you are facing? They look similar.

hoist-non-react-statics issue on rollup.js build

i am having issues while trying to build my storybook with rollup.js, in my react components i am using #mui/material and in their installation page its asked to also install both packages called #emotion/react and #emotion/styled but whenever i try building with rollup.js npm run build-lib i get the following error below which i think might be related to #mui/material or #emotion/react not very sure but how can i resolve this? thanks very much.
error
> rollup -c
[!] Error: 'default' is not exported by node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js, imported by node_modules/#emotion/react/_isolated-hnrs/dist/emotion-react-_isolated-hnrs.esm.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/#emotion/react/_isolated-hnrs/dist/emotion-react-_isolated-hnrs.esm.js (1:7)
1: import hoistNonReactStatics$1 from 'hoist-non-react-statics';
^
2:
3: // this file isolates this package that is not tree-shakeable
Error: 'default' is not exported by node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js, imported by node_modules/#emotion/react/_isolated-hnrs/dist/emotion-react-_isolated-hnrs.esm.js
peerDependencies
"peerDependencies": {
"prop-types": "^15.8.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "^6.3.0",
"react-router-hash-link": "^2.4.3"
},
dependencies
"dependencies": {
"#babel/preset-stage-0": "^7.8.3",
"#emotion/react": "^11.9.0",
"#emotion/styled": "^11.8.1",
"#fontsource/dm-sans": "^4.5.6",
"#mui/icons-material": "^5.6.2",
"#mui/material": "^5.6.2",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.1.1",
"#testing-library/user-event": "^14.1.1",
"react-scripts": "5.0.1",
"react-slick": "^0.29.0",
"rollup-plugin-terser": "^7.0.2",
"slick-carousel": "^1.8.1",
"url-loader": "^4.1.1",
"web-vitals": "^2.1.4"
},
devDependencies
"devDependencies": {
"#babel/core": "^7.17.9",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
"#rollup/plugin-image": "^2.1.1",
"#rollup/plugin-node-resolve": "^13.2.1",
"#storybook/addon-actions": "^6.4.22",
"#storybook/addon-essentials": "^6.4.22",
"#storybook/addon-interactions": "^6.4.22",
"#storybook/addon-links": "^6.4.22",
"#storybook/builder-webpack5": "^6.4.22",
"#storybook/manager-webpack5": "^6.4.22",
"#storybook/react": "^6.4.22",
"#storybook/testing-library": "0.0.11",
"#svgr/webpack": "^6.2.1",
"babel-loader": "^8.2.5",
"babel-preset-gatsby": "^2.12.1",
"babel-preset-stage-0": "^6.24.1",
"css-loader": "^6.7.1",
"path": "^0.12.7",
"prop-types": "^15.8.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"rollup": "^2.70.2",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"style-loader": "^3.3.1",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2"
}
scripts
"scripts": {
"build": "webpack",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"build-lib": "rollup -c"
},
Was having the same error, I was able to resolve this by using the #rollup/plugin-commonjs in my rollup.config.js
https://github.com/rollup/plugins/tree/master/packages/commonjs#custom-named-exports

Adding MUI Component to Component Library results in Error "Hooks can only be called inside of the body of a functional component"

I have a component library that exports components
// Test.tsx
import React from 'react';
const Test = () => <p>Test</p>;
export default Test;
and
// TestB.tsx
import React from 'react';
import { Typography } from '#material-ui/core';
const TestB = () => <Typography>TestB</Typography>;
export default TestB
In my other package I'm importing the components as so
import React from 'react';
import { Box } from '#components';
import { Test, TestB } from 'component-library';
const Example = (): JSX.Element | null => {
return (
<Box mb={3}>
<Test />
<TestB />
</Box>
);
};
export default Example;
When I import Test I get the expected <p>Test</p> but when I import TestB I get the following error:
react.development.js:1476 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
at resolveDispatcher (react.development.js:1476)
at Object.useContext (react.development.js:1484)
at useTheme (useTheme.js:4)
at useStyles (makeStyles.js:222)
at WithStyles (withStyles.js:55)
at renderWithHooks (react-dom.development.js:14803)
at updateForwardRef (react-dom.development.js:16816)
at beginWork (react-dom.development.js:18645)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
I have confirmed react and react-dom are both on the version 16.9.0
-- though this doesn't seem relevant since it will work with Test, but not TestB
I don't see how I could be breaking the Rules of Hooks with the implementation of TestB since it doesn't use any hooks
I have tried removing all but one version inclusion of react through package.json
-- again this doesn't seem relevant since it will work with Test, but not TestB
Component Library package.json dependencies
"dependencies": {
"#material-ui/core": "4.11.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^17.0.2",
"react-svg": "^13.0.6"
},
"devDependencies": {
"#babel/core": "^7.14.3",
"#types/jest": "^24.0.24",
"#typescript-eslint/eslint-plugin": "^4.25.0",
"#typescript-eslint/parser": "^4.25.0",
"babel-loader": "^8.2.2",
"eslint": "^7.27.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"jest": "^24.9.0",
"rollup": "^1.27.13",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.0",
"rollup-plugin-typescript2": "^0.25.3",
"standard": "^14.3.1",
"standard-prettier": "^1.0.1",
"ts-jest": "^24.2.0",
"typescript": "^3.7.3"
},
Projects package.json dependencies
"dependencies": {
"#babel/core": "^7.1.6",
"#babel/plugin-proposal-class-properties": "^7.1.0",
"#babel/plugin-proposal-object-rest-spread": "^7.0.0",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/plugin-transform-flow-strip-types": "^7.1.6",
"#babel/plugin-transform-modules-commonjs": "^7.4.3",
"#babel/polyfill": "^7.6.0",
"#babel/preset-env": "^7.9.0",
"#babel/preset-react": "^7.0.0",
"#babel/preset-typescript": "^7.9.0",
"#date-io/moment": "1.x",
"#emotion/core": "^10.0.10",
"#material-ui/core": "^4.11.4",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.56",
"#material-ui/pickers": "^3.2.10",
"#stripe/react-stripe-js": "^1.1.2",
"#stripe/stripe-js": "^1.4.0",
"#styled-system/css": "^1.0.3",
"#typeform/embed": "^0.5.12",
"attr-accept": "^1.1.0",
"autoprefixer": "^8.0.0",
"awesome-typescript-loader": "^4.0.0",
"axios": "^0.19.2",
"babel-loader": "^8.0.4",
"babel-plugin-dynamic-import-node": "^2.3.0",
"babel-plugin-styled-components": "^1.10.0",
"classnames": "^2.2.5",
"compression-webpack-plugin": "^1.0.0",
"core-js": "^3.2.1",
"cropperjs": "^1.3.3",
"css-hot-loader": "^1.3.6",
"css-loader": "^0.28.7",
"d3": "^6.2.0",
"d3-selection": "^2.0.0",
"date-fns": "^2.9.0",
"dot-prop-immutable": "^1.4.0",
"downshift": "^5.0.3",
"emotion-theming": "^10.0.10",
"empty": "^0.10.1",
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"enzyme-to-json": "^3.3.4",
"eslint": "^7.3.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-flowtype": "^2.46.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jest": "^21.5.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.5.1",
"extract-text-webpack-plugin": "^3.0.1",
"faker": "^4.1.0",
"fetch-mock": "^6.5.2",
"file-loader": "^0.11.2",
"file-saver": "^2.0.2",
"final-form": "^4.20.1",
"final-form-arrays": "^3.0.2",
"final-form-calculate": "^1.3.1",
"glob": "^7.1.2",
"hellosign-embedded": "^2.8.0",
"identity-obj-proxy": "^3.0.0",
"isomorphic-fetch": "^2.2.1",
"js-yaml": "^3.10.0",
"jwt-decode": "^2.2.0",
"lint-staged": "^10.2.11",
"loaders.css": "^0.1.2",
"lost": "^8.2.0",
"components": "https://github.com/example/components#dev",
"mock-geolocation": "^1.0.11",
"moment": "2.24.0",
"moment-locales-webpack-plugin": "^1.2.0",
"moment-timezone": "^0.5.28",
"node-sass": "^4.12.0",
"notistack": "^0.9.11",
"numeral": "^2.0.6",
"path-complete-extname": "^1.0.0",
"postcss-automath": "^1.0.1",
"postcss-calc": "^7.0.2",
"postcss-flexbugs-fixes": "^3.2.0",
"postcss-font-magician": "^2.0.0",
"postcss-import": "^10.0.0",
"postcss-initial": "^2.0.0",
"postcss-loader": "^2.0.6",
"postcss-smart-import": "^0.7.5",
"precss": "^2.0.0",
"prettier-eslint": "^8.7.0",
"prop-types": "^15.5.10",
"qs": "^6.5.1",
"ramda": "^0.27.1",
"rc-time-picker": "^3.7.2",
"react": "17.0.2",
"react-addons-shallow-compare": "^15.6.0",
"react-confetti": "^6.0.0",
"react-content-loader": "^4.0.1",
"react-cropper": "^1.0.1",
"react-dates": "^21.8.0",
"react-datetime": "^2.16.3",
"react-dom": "17.0.2",
"react-final-form": "^6.5.1",
"react-final-form-arrays": "^3.1.2",
"react-final-form-listeners": "^1.0.3",
"react-hot-loader": "^4.6.3",
"react-measure": "^2.0.2",
"react-modal": "^3.8.1",
"react-motion": "^0.5.1",
"react-onclickoutside": "^6.7.0",
"react-portal": "^4.0.0",
"react-pose": "^4.0.8",
"react-pose-text": "^3.1.0",
"react-query": "^2.5.13",
"react-redux": "^7.2.0",
"react-resize-detector": "^6.6.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-select": "^1.0.0-rc.10",
"react-svg-loader": "^1.1.1",
"react-switch": "^2.0.0",
"react-table": "^7.0.1",
"react-tabs": "^2.2.2",
"react-test-renderer": "^16.5.2",
"react-text-mask": "^5.4.3",
"react-textfit": "^1.1.0",
"react-use": "^15.3.4",
"react-virtualized-auto-sizer": "^1.0.2",
"react-window": "^1.8.6",
"react-window-infinite-loader": "^1.0.5",
"react-youtube": "^7.5.0",
"react_ujs": "^2.4.4",
"recompose": "^0.26.0",
"redux": "^4.0.1",
"redux-actions": "^2.6.5",
"redux-analytics": "^0.3.1",
"redux-form": "^8.3.6",
"redux-mock-store": "^1.4.0",
"redux-observable": "^1.1.0",
"redux-persist": "^5.6.12",
"redux-responsive": "^4.3.8",
"redux-thunk": "^2.2.0",
"regenerator-runtime": "^0.11.0",
"reselect": "^3.0.1",
"resolve-url-loader": "^2.1.0",
"rxjs": "^6.4.0",
"sass-loader": "^6.0.6",
"shortid": "^2.2.8",
"sinon": "^6.3.5",
"start-server-and-test": "^1.7.11",
"style-loader": "^0.18.2",
"styled-components": "^4.1.3",
"styled-normalize": "^8.0.4",
"styled-system": "^3.2.1",
"svg-react-loader": "^0.4.5",
"swr": "^0.2.0",
"ts-jest": "^23.1.3",
"typescript": "^3.8.3",
"typings-for-css-modules-loader": "^1.7.0",
"warnings-to-errors-webpack-plugin": "^2.0.1",
"webpack": "^3.12.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-dev-server": "^2.7.1",
"webpack-manifest-plugin": "^1.3.1",
"webpack-merge": "^4.1.0",
"whatwg-fetch": "^3.0.0"
},
"devDependencies": {
"#svgr/cli": "^5.4.0",
"#testing-library/cypress": "^6.0.0",
"#testing-library/react": "^8.0.6",
"#types/classnames": "^2.2.3",
"#types/faker": "^4.1.4",
"#types/fetch-mock": "^6.0.3",
"#types/intercom-web": "^2.8.7",
"#types/jest": "^25.2.3",
"#types/jwt-decode": "^2.2.1",
"#types/moment-timezone": "^0.5.4",
"#types/qs": "^6.5.1",
"#types/query-string": "^6.3.0",
"#types/ramda": "^0.27.36",
"#types/react": "^16.7.20",
"#types/react-content-loader": "^3.1.4",
"#types/react-dates": "^17.1.14",
"#types/react-dom": "^16.0.11",
"#types/react-loadable": "^5.4.2",
"#types/react-measure": "^2.0.2",
"#types/react-modal": "^3.8.2",
"#types/react-motion": "^0.0.26",
"#types/react-onclickoutside": "^6.0.3",
"#types/react-redux": "^7.1.9",
"#types/react-router-dom": "^5.1.3",
"#types/react-select": "^1.2.7",
"#types/react-table": "^7.0.13",
"#types/react-test-renderer": "^16.0.2",
"#types/recompose": "^0.26.1",
"#types/redux-actions": "^2.6.0",
"#types/redux-form": "^7.4.16",
"#types/redux-mock-store": "^1.0.0",
"#types/shortid": "^0.0.29",
"#types/sinon": "^5.0.5",
"#types/styled-components": "^4.1.18",
"#types/styled-system": "^3.1.1",
"#types/webpack-env": "^1.13.6",
"#typescript-eslint/eslint-plugin": "^3.4.0",
"#typescript-eslint/parser": "^3.4.0",
"cypress": "6.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.0.1",
"miragejs": "^0.1.35",
"pre-commit": "^1.2.2",
"prettier": "^2.0.5"
},
Any thoughts?
Moving everything to devDependencies for the most part and adding the prepare script seemed to be what I was missing.
My package.json ended up looking like this
{
"version": "0.1.0",
"main": "dist/index.js",
"module": "build/index.es.js",
"jsnext:main": "build/index.es.js",
"files": ["dist", "build"],
"scripts": {
"prepare": "npm run build",
"build": "rollup -c",
"format": "prettier-standard --format",
"test": "jest --coverage",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"lint": "eslint 'src/**/*.{{j,t}s,{j,t}sx}'",
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {},
"peerDependencies": {
"#material-ui/core": "4.11.4",
"react": "^16"
},
"devDependencies": {
"#babel/core": "^7.14.3",
"#material-ui/core": "4.11.4",
"#storybook/addon-actions": "^6.2.9",
"#storybook/addon-essentials": "^6.2.9",
"#storybook/addon-knobs": "^6.2.9",
"#storybook/addon-links": "^6.2.9",
"#storybook/react": "^6.2.9",
"#types/jest": "^24.0.24",
"#typescript-eslint/eslint-plugin": "^4.25.0",
"#typescript-eslint/parser": "^4.25.0",
"babel-loader": "^8.2.2",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-react": "^7.23.2",
"eslint": "^7.27.0",
"jest": "^24.9.0",
"react-dom": "^17.0.2",
"react-is": "^17.0.2",
"react-svg": "^13.0.6",
"react": "^17.0.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.0",
"rollup-plugin-typescript2": "^0.25.3",
"rollup": "^1.27.13",
"standard-prettier": "^1.0.1",
"standard": "^14.3.1",
"storybook-addon-paddings": "^4.1.1",
"storybook-dark-mode": "^1.0.8",
"ts-jest": "^24.2.0",
"typescript": "^3.7.3"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
},
"standard": {
"ignore": [
"node_modules/",
"build/"
]
}
}
And rollup.config by request
import typescript from 'rollup-plugin-typescript2'
import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
import resolve from 'rollup-plugin-node-resolve'
import pkg from './package.json'
export default {
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true
},
{
file: pkg.module,
format: 'es',
exports: 'named',
sourcemap: true
}
],
external: ["react", "#material-ui/core", "react-is"],
plugins: [
external(),
resolve(),
typescript({
rollupCommonJSResolveHack: true,
exclude: [
'**/__tests__/**',
'**/*.stories.*'
],
clean: true
}),
commonjs({
include: ['node_modules/**'],
namedExports: {}
})
]
}
I had exactly the same setup and problem, but I focussed too much on the problem, that the imported MUI-component is calling this error. But when you read the error message closely, there is also the possibility of "You might have more than one copy of React in the same app". The reason for my wrong conclusion was that my app did not throw an error once I removed the MUI component. Accordingly, it could not be the React error. Unfortunately, this was not the case! After some more desperate research on every detail, I found this post: Invalid Hook call....
So inside the APP folder (which is using your library) I ran the command npm link <path_to_local_library>/node_modules/react, which fixed my error. See the details for npm link.

React Native Bugsnag error: TypeError Properties can only be defined on Objects [native code] defineProperty

We have an react-native app with 25k+ users and have gotten over 1000 crashes over the last 3 months reported in bugsnag. The crash typically happens within 1 sec of startup, but sometimes it takes a few seconds. We have not been able to reproduce this in development. It is happening on both ios and android. The only thing we have to go off of is the stacktrace provided by bugsnag:
iOS bugsnag stack trace:
TypeError Properties can only be defined on Objects.
[native code] defineProperty
node_modules/react-redux/lib/connect/mergeProps.js:54:21
node_modules/react-native/node_modules/#babel/runtime/helpers/typeof.js:17:17 _get
node_modules/react-redux/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js:100:11
node_modules/react-native/node_modules/#babel/runtime/helpers/typeof.js:17:17 _get
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59 res
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59 _toConsumableArray
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59 _defineProperties
[native code] value
Android bugsnag stack trace:
TypeError Properties can only be defined on Objects.
[native code] defineProperty
node_modules/react-redux/lib/utils/isPlainObject.js:20:19
node_modules/react-native/node_modules/#babel/runtime/helpers/typeof.js:17:17 _get
node_modules/react-redux/lib/components/connectAdvanced.js:130:29
node_modules/react-native/node_modules/#babel/runtime/helpers/typeof.js:17:17 _get
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59 _typeof2
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59 RCTDeviceEventEmitter
node_modules/react-native/node_modules/#babel/runtime/helpers/toConsumableArray.js:8:59 _defineProperties
[native code] value
The stack traces leads me to believe it has something to do with react-redux.
However I don't believe this issue happened before upgrading to RN v 0.62 which leads me to believe it might have something to do with RN 0.62
here are the dependencies in the package.json:
"dependencies": {
"#emotion/core": "^10.0.16",
"#fragaria/address-formatter": "^2.0.5",
"#react-native-community/art": "^1.0.3",
"#react-native-community/async-storage": "^1.8.0",
"#react-native-community/cameraroll": "^1.3.0",
"#react-native-community/clipboard": "^1.2.2",
"#react-native-community/datetimepicker": "^2.1.0",
"#react-native-community/masked-view": "^0.1.6",
"#react-native-community/netinfo": "^5.9.0",
"#react-native-firebase/app": "^6.4.0",
"#react-native-firebase/crashlytics": "^6.4.0",
"#react-native-firebase/messaging": "^6.4.0",
"#react-navigation/bottom-tabs": "^5.1.1",
"#react-navigation/drawer": "^5.0.6",
"#react-navigation/native": "^5.0.9",
"#react-navigation/stack": "^5.1.1",
"apisauce": "^0.14.3",
"bugsnag-react-native": "^2.20.0",
"bugsnag-sourcemaps": "^1.0.4",
"emotion-theming": "^10.0.14",
"lodash": "^4.17.10",
"moment": "^2.22.2",
"moment-round": "^1.0.1",
"prop-types": "15.6.0",
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-app-auth": "^5.0.0",
"react-native-audio-recorder-player": "^2.4.3",
"react-native-call-detection": "^1.9.0",
"react-native-camera": "git+https://git#github.com/react-native-community/react-native-camera.git",
"react-native-config": "^0.12.0",
"react-native-device-info": "^5.0.0",
"react-native-fast-image": "^7.0.2",
"react-native-geolocation-service": "^4.0.0",
"react-native-gesture-handler": "^1.6.0",
"react-native-google-places-autocomplete": "^1.4.1",
"react-native-intercom": "^13.1.0",
"react-native-keyboard-aware-scroll-view": "^0.9.1",
"react-native-maps": "0.26.1",
"react-native-modal": "^11.4.0",
"react-native-notifications": "^3.1.2",
"react-native-open-maps": "^0.3.4",
"react-native-permissions": "~1.1.1",
"react-native-pie": "^0.6.1",
"react-native-progress": "^4.1.2",
"react-native-rate": "1.1.10",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.0.0-beta.10",
"react-native-snap-carousel": "^3.8.4",
"react-native-sound-player": "^0.10.3",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^12.0.3",
"react-native-swipe-list-view": "^2.0.3",
"react-native-vector-icons": "6.6.0",
"react-native-video": "^4.4.5",
"react-native-video-controls": "^2.6.0",
"react-native-webview": "^8.1.1",
"react-redux": "^7.1.0",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-mock-store": "^1.5.4",
"redux-persist": "^6.0.0",
"redux-saga": "^1.1.3",
"reselect": "^4.0.0",
"rn-fetch-blob": "^0.12.0"
},
"devDependencies": {
"#babel/core": "^7.6.2",
"#babel/plugin-proposal-class-properties": "^7.4.0",
"#babel/preset-env": "^7.4.3",
"#babel/runtime": "^7.9.6",
"#storybook/addon-actions": "5.1.11",
"#storybook/addon-knobs": "5.1.11",
"#storybook/addon-links": "5.1.11",
"#storybook/addon-notes": "5.1.11",
"#storybook/addon-ondevice-actions": "5.1.11",
"#storybook/addon-ondevice-knobs": "5.1.11",
"#storybook/addon-ondevice-notes": "5.1.11",
"#storybook/addon-storyshots": "5.1.11",
"#storybook/addons": "5.1.11",
"#storybook/react-native": "5.1.11",
"babel-eslint": "^10.0.2",
"babel-jest": "^24.9.0",
"babel-loader": "^7.1.5",
"babel-plugin-module-resolver": "^3.2.0",
"babel-polyfill": "7.0.0-beta.3",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^13.0.0",
"eslint-import-resolver-babel-module": "^5.1.0",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "2.2.3",
"eslint-plugin-react": "7.12.4",
"jest": "24.9.0",
"jest-plugin-context": "^2.9.0",
"jetifier": "^1.6.4",
"metro-react-native-babel-preset": "^0.58.0",
"react-addons-test-utils": "~15.4.1",
"react-dom": "16.8.3",
"react-native-testing-library": "^2.1.0",
"react-test-renderer": "^16.13.1",
"wd": "^1.11.4"
}
Any clues as to what the issue may be?
I met the same error "TypeError Properties can only be defined on Objects [native code] defineProperty". I solved it by replacing some code using #react-native-firebase/messaging.
you can try replacing the code
`
useEffect(() => {
messaging().getToken().then(token => {
//some logic code
});
return messaging().onTokenRefresh(token => {
//some logic code
});
}, []);
`
with
`
useEffect(() => {
messaging().getToken().then(token => {
//some logic code
});
messaging().onTokenRefresh(token => {
//some logic code
});
}, []);
`

Resources