I have installed yarn add react-native-svg this library as I want to design circular progress bar on a react-native app screen. I am getting this below error and I have tried everything possible but its not getting resolved. I am also tried to manually link the library (We don't need to do that as I am using react-native >0.60. It provides auto-linking).
ERROR Invariant Violation: requireNativeComponent: "RNSVGCircle" was not found in the UIManager.
The code where it's throwing exception is as below
import React from 'react';
import { View, Text } from 'react-native';
import { Circle } from 'react-native-svg';
const CircularProgressBarTest = ({ progress }) => {
const circumference = 2 * Math.PI * 100;
const strokeDashoffset = circumference - (progress / 100) * circumference;
return (
<View>
<Circle
cx={200}
cy={200}
r={100}
stroke="#000"
strokeWidth={20}
fill="transparent"
strokeDasharray={circumference}
strokeDashoffset={strokeDashoffset}
/>
<Text>{progress}%</Text>
</View>
);
};
export default CircularProgressBarTest;
My package.json file looks like this
"dependencies": {
"#dietime/react-native-date-picker": "^1.2.0",
"#react-native-async-storage/async-storage": "^1.14.1",
"#react-native-community/datetimepicker": "^6.5.2",
"#react-native-community/masked-view": "^0.1.10",
"#react-native-community/push-notification-ios": "^1.8.0",
"#react-native-firebase/app": "^12.0.0",
"#react-native-firebase/auth": "^12.0.0",
"#react-native-firebase/firestore": "^12.0.0",
"#react-native-picker/picker": "^1.16.1",
"#react-navigation/native": "^5.9.4",
"#react-navigation/stack": "^5.14.4",
"expo": "~42.0.1",
"expo-constants": "~11.0.1",
"expo-font": "^9.1.0",
"expo-linear-gradient": "^12.0.1",
"expo-notifications": "^0.12.3",
"expo-task-manager": "~9.2.2",
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-chart-kit": "^6.12.0",
"react-native-circular-progress": "*",
"react-native-circular-progress-indicator": "^4.4.2",
"react-native-date-picker": "^4.2.5",
"react-native-elements": "^3.4.2",
"react-native-gesture-handler": "~1.10.2",
"react-native-linear-gradient": "^2.6.2",
"react-native-modalize": "^2.0.8",
"react-native-paper": "^4.8.1",
"react-native-radio-check": "^1.0.0",
"react-native-reanimated": "^2.13.0",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "~3.4.0",
"react-native-snap-carousel": "^3.9.1",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^13.6.0",
"react-native-unimodules": "~0.14.5",
"react-native-vector-icons": "^8.1.0",
"react-usestateref": "^1.0.5"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#babel/runtime": "^7.12.5",
"#react-native-community/eslint-config": "^2.0.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"
},
"jest": {
"preset": "react-native"
}
}
Problems with Proguard
When Proguard is enabled (which it is by default for Android release builds), it causes runtime error. To avoid this, add an exception to android/app/proguard-rules.pro:
-keep public class com.horcrux.svg.** {*;}
If you have build errors, then it might be caused by caching issues, please try:
watchman watch-del-all
rm -fr $TMPDIR/react-*
react-native start --reset-cache
Or,
rm -rf node_modules
yarn
react-native start --reset-cache
Took from the Troubleshooting area of react-native-svg
Related
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
So I installed WatermelonDB for React Native and wanted to use it. I did everything exactly like in the installation guide but it seems like it didn't work.
This is the error I get:
This are my dependecies:
"dependencies": {
"#gorhom/bottom-sheet": "^4.1.5",
"#nozbe/watermelondb": "^0.24.0",
"#react-native-async-storage/async-storage": "^1.15.15",
"#react-native-clipboard/clipboard": "^1.8.5",
"#react-native-community/blur": "^3.6.0",
"#react-native-community/netinfo": "^7.1.7",
"#react-navigation/bottom-tabs": "^6.0.9",
"#react-navigation/native": "^6.0.6",
"#react-navigation/native-stack": "^6.2.5",
"#react-navigation/stack": "^6.0.11",
"audit": "^0.0.6",
"fix": "^0.0.6",
"react": "17.0.2",
"react-native": "0.66.4",
"react-native-background-timer": "^2.4.1",
"react-native-device-info": "^8.4.8",
"react-native-geolocation-service": "^5.3.0-beta.4",
"react-native-gesture-handler": "^2.2.0",
"react-native-hyperlink": "^0.0.19",
"react-native-image-crop-picker": "^0.37.2",
"react-native-localize": "^2.1.7",
"react-native-maps": "^0.30.1",
"react-native-mmkv": "^2.0.0",
"react-native-pinchable": "^0.2.1",
"react-native-reanimated": "^2.3.1",
"react-native-safe-area-context": "^3.3.2",
"react-native-screens": "^3.10.2",
"react-native-svg": "^12.1.1",
"react-native-typing-animation": "^0.1.7",
"rn-fetch-blob": "^0.12.0"
},
It does not matter if I try it with or without JSI. Does not work all the time.
I also use kotlinVersion = '1.4.21'
The docs are actually wrong. For everybody having the same problem:
index.js
...
myScheme,
...
has to become
scheme: myScheme,
React don't see 'file-saver' although it was installed.
I made yarn add file-saver, then yarn install and still nothing.
It's imported like :
import { saveAs } from 'file-saver';
in package.json looks like:
"dependencies": {
"#emotion/is-prop-valid": "^1.1.0",
"#emotion/react": "^11.4.1",
"#emotion/styled": "^11.3.0",
"#material-ui/core": "^4.12.2",
"#material-ui/icons": "^4.11.2",
"#mui/lab": "^5.0.0-alpha.48",
"#mui/material": "^5.0.1",
"#types/file-saver": "^2.0.3",
"#types/react-table": "^7.7.2",
"axios": "0.21.1",
"core-js": "^3.6.5",
"date-fns": "^2.24.0",
"document-register-element": "1.13.1",
"file-saver": "^2.0.5",
thanks
Try adding also "#types/file-saver": "^2.0.5", apart of "file-saver": "^2.0.5"
I want to use Ant Design with Snowpack. I followed the And Design docs and installed antd but whenever I run my application the dependency can't be resolved.
I get the following error message:
[snowpack] Import "antd" could not be resolved.
If this is a new package, re-run Snowpack with the --reload flag to rebuild.
If Snowpack is having trouble detecting the import, add "install": ["antd"] to your Snowpack config file.
My App.tsx:
import React from 'react';
import './App.css';
import { Button } from 'antd';
function App(): JSX.Element {
return (
<div className="App">
<Button type="primary">Button</Button>
</div>
);
}
export default App;
My package.json dependencies:
"dependencies": {
"antd": "^4.6.2",
"axios": "^0.20.0",
"postcss": "^7.0.32",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hook-form": "^6.7.0",
"tailwindcss": "^1.7.6"
},
"devDependencies": {
"#snowpack/app-scripts-react": "^1.10.0",
"#testing-library/jest-dom": "^5.5.0",
"#testing-library/react": "^10.0.3",
"#types/react": "^16.9.35",
"#types/react-dom": "^16.9.8",
"#types/snowpack-env": "^2.3.0",
"#typescript-eslint/eslint-plugin": "^4.0.1",
"#typescript-eslint/parser": "^4.0.1",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.0",
"jest": "^26.2.2",
"postcss-cli": "^7.1.2",
"prettier": "^2.0.5",
"snowpack": "^2.9.0",
"typescript": "^3.9.7"
}
Am I missing something?
Make sure antd is already installed. Try this in snowpack.config.js:
module.exports = {
mount: {
public: "/",
src: "/_dist_",
},
installOptions: {
namedExports: ["antd"],
},
};
I am trying to get started in building a react application using konva, react-konva.
I built a basic react component:
import React, { Component } from "react";
import { Stage } from "react-konva";
import Square from "./Square.jsx";
class Map extends Component {
render() {
return (
<Stage height={100} width={100}>
<Layer>
</Layer>
</Stage>
);
}
}
export default Map;
and also a test using jest:
/* global beforeEach describe expect it */
import { shallow } from "enzyme";
import React from "react";
import Map from "../Map";
function createComponent() {
const wrapper = shallow(
<Map />
);
return wrapper;
}
describe("Map component test", () => {
describe("When initializing the component", () => {
let sut;
beforeEach(() => {
sut = createComponent();
});
it("it should render a Stage component", () => {
expect(sut.find("Stage").exists()).toBe(true);
});
});
});
When this test runs, I get the following error:
TypeError: Cannot read property 'webkitBackingStorePixelRatio' of null
at node_modules/konva/konva.js:1291:36
at node_modules/konva/konva.js:1298:7
at Object.<anonymous> (node_modules/konva/konva.js:1477:3)
at Object.<anonymous> (node_modules/react-konva/src/react-konva.js:4:13)
at Object.<anonymous> (src/mapping/Map.jsx:2:19)
at Object.<anonymous> (src/mapping/MapContainer.js:3:12)
at Object.<anonymous> (src/App.jsx:3:21)
at Object.<anonymous> (src/tests/App.spec.js:5:12)
My dependencies from package.json:
"dependencies": {
"konva": "^1.6.3",
"prop-types": "^15.5.10",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-konva": "^1.1.3",
"react-redux": "^5.0.5",
"redux": "^3.7.1"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"canvas": "^1.6.5",
"chalk": "^1.1.3",
"coveralls": "^2.13.1",
"css-loader": "^0.28.4",
"enzyme": "^2.8.2",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.5.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-react": "^7.1.0",
"eslint-watch": "^3.1.2",
"html-webpack-plugin": "^2.28.0",
"jest": "^20.0.4",
"jsdom": "^11.1.0",
"node-gyp": "^3.6.2",
"npm-run-all": "^4.0.2",
"react-test-renderer": "^15.6.1",
"redux-mock-store": "^1.2.3",
"style-loader": "^0.18.2",
"webpack": "^3.0.0"
}
I'm sure that this is related to node setup, but I am unsure of the correct way to do it. Can anyone help?
I fixed it by installing and using konva-node in my test:
import Konva from 'konva-node';
I also had to specify that it's not used in the browser before executing any tests:
Konva.isBrowser = false;
I am using the following dependencies:
"dependencies": {
"axios": "^0.18.0",
"konva": "^2.5.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-konva": "^16.5.2",
"react-scripts": "2.0.5"
},
"devDependencies": {
"chai": "^4.2.0",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.7.0",
"konva-node": "^0.5.5",
"sinon": "^7.1.1",
"sinon-chai": "^3.2.0"
},
There are several options:
The one mentioned by Alpar. It works for me but it requires building of old node-canvas version.
Using https://github.com/hustcc/jest-canvas-mock. If you are using Create React App just add import 'jest-canvas-mock' in your setupTests.js
Theoretically npm i -D canvas should solve this problem as well but I have not managed to make it work. Read here https://github.com/jsdom/jsdom/issues/1782 for more ideas.