react-native-web: Can't resolve 'react-native-web/dist/exports/ViewPropTypes' after upgrading to 0.12.1
I have tried to upgrade from react-native-web
v0.11.7 to 0.12.1 and it breaks my app:
Module not found: Can't resolve 'react-native-web/dist/exports/ViewPropTypes' in '/home/dka/workspace/test-native/node_modules/react-native-swipe-list-view/components'
See:
Related to:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 57 (2 by maintainers)
Commits related to this issue
- Remove ViewPropTypes references ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to Kabangi/react-native-gifted-chat by Kabangi 4 years ago
- Remove ViewPropTypes references (#1694) ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to FaridSafi/react-native-gifted-chat by Kabangi 4 years ago
- Remove ViewPropTypes references (#1694) ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to shamilovtim/react-native-gifted-chat by Kabangi 4 years ago
- Remove ViewPropType. This is depreacted and now longer exists in react-native-web. See: https://github.com/necolas/react-native-web/issues/1537 — committed to miracle2k/react-native-super-grid by miracle2k 4 years ago
- Remove ViewPropType. This is depreacted and now longer exists in react-native-web. See: https://github.com/necolas/react-native-web/issues/1537 — committed to TigerWFH5h/saleel7 by TigerWFH5h 2 years ago
- Remove ViewPropTypes references (#1694) ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to daya110/react-native-gifted-chat by deleted user 4 years ago
- Remove ViewPropTypes references (#1694) ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to spartacus0816/react-native by deleted user 4 years ago
- Remove ViewPropTypes references (#1694) ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to secretstardev/react-native-gifted-chat by Kabangi 4 years ago
- Remove ViewPropTypes references (#1694) ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to osk-poita121/react-native-gifted-chat by Kabangi 4 years ago
- Remove ViewPropTypes references (#1694) ViewPropTypes is no longer supported on react-native-web > 0.12.0 as described on this issue https://github.com/necolas/react-native-web/issues/1537 — committed to Dolloong/react-native-chat by Dolloong 4 years ago
A lot of other packages are not able to be compiled after upgrading to 0.12.x We use react-native-web as alias for react-native. So, if react-native still support prop types exports, but as deprecated, i think this package should behave in the same way: support them, but deprecated.
It was removed as mentioned in the release notes https://github.com/necolas/react-native-web/releases/tag/0.12.0
Hello developers, I had the same issue. Before, I manually copied the library I was using in my code, but it turns out was not the best way so I created a workaround.
Explanation If you mock ViewPropTypes in node_modules/react-native-web/dist/index.js the error will go away. So what I did is I wrote some batch file for Windows, bash for Unix-like, Python for both, it is up to you to decide which one. Just copy and paste.
Workaround
Copy & paste the code
Python: fix.py OS-agnostic, use this if possible
Windows Batch: fix.bat
Unix-like bash: fix.sh
I added in the bash a cool if-else so that you can run it infinitely without duplicating it.
Please replace PATH_TO_NODE_MODULES with the path to your node_modules folder. For example, if you at your root folder it should be “node_modules”
Each time you run
npm install
| ``yarn install` or when you add a new package, the fix is removed, since the package refreshed. To overcome this, modify your scripts and add a post-install command that is called after. Basically, it would execute your bat script each time you hit npm or yarn install.With the python version
"postinstall": "python fix.py"
With .bat or .sh
"postinstall": "fix"
Hope it would help. It works for me. Don’t hesitate to ask me anything. Thanks! Franz
Building on @franznkemaka 's script (by the way thank you it fixed the issue for me), here’s my version, for bash:
NOTE: depending on your OS - you might need to run: “chmod +x ./fix-for-web.sh”
"scripts": { "start": "expo start", ... "postinstall": "bash ./fix-for-web.sh" },
My WORKING solution for “Module not found” from answers above tested on “expo”: “^39.0.0”:
var ViewPropTypes = { style: null } export default ViewPropTypes;
Import above in react-native-web/dist/index.js export { default as ViewPropTypes } from ‘./exports/ViewPropTypes’;
run expo r -c
use patch-package
first, add script at package.json (postinstall means after effect installing)
second, install patch-package
third, open
react-native-web/dist/index.js
and editfourth, run patch-package
check created file at rootDir/patches
good luck
refer : https://www.npmjs.com/package/patch-package
Hello. I have the same issue like this. My import is like this
import {Overlay as BaseOverlay, Button, Text} from 'react-native-elements/src/index';
And errors in terminal
./node_modules/react-native-elements/src/config/ViewPropTypes.js Attempted import error: 'ViewPropTypes' is not exported from 'react-native-web' (imported as 'RNViewPropTypes').
I created the react app using
create-react-native-web-app
command.System: Windows 10 IDE: VS Code “node”: v13.6.0 “react”: “^16.13.0” “react-native”: “0.61.5” “react-native-elements”: “^1.0.0-beta8” “react-native-web”: “^0.12.2”
What is the solution to fix this issue? Thanks for your reply.
Module not found: Can’t resolve ‘react-native-web/dist/exports/ViewPropTypes’ after update to expo sdk 39.0
Hello @willerpp, it should normally work. May I please see the content of your autofix.bat?
Possible fixes:
Did you try to run the script manually via cmd? The script will only run if something is installed. For the first time, I had to run it manually, as I already installed my packages.
Open node_modules/react-native-web/dist/index.js. Can you see this at the bottom
export const ViewPropTypes = { style: null };
Thanks! Franz
Hello @karpov-denys,
When you add
export const ViewPropTypes = { style: null }
toPATH_TO_NODE_MODULES/react-native-web/dist/index.js
. You mock ViewPropTypes, by exporting an object.Check out my answer above https://github.com/necolas/react-native-web/issues/1537#issuecomment-619969653
I updated the answer, now there is a batch script, a bash script, and a python script. I recommend you to use the Python version since it works on both Unix-like OS & Windows having Python installed.
Best regards, Franz
Ok well, I have added it manually to the file and it works, let me try to run the script manually. thank you so much for your response.
On Tue, Jun 16, 2020 at 10:38 AM Franz Nkemaka notifications@github.com wrote:
Building off @AndreiMsk 's solution, I resolved this by adding the following to my
fix-for-web.sh
post
script:@franznkemaka have a look at https://www.npmjs.com/package/patch-package as it makes patching stuff like this much easier 😊
Hello @aguilared . I had the same issue. Before, I manually copied the library I was using in my code, but it turns out was not the best way so I created a workaround.
Check out my comment above: https://github.com/necolas/react-native-web/issues/1537#issuecomment-619969653
It works for me. Don’t hesitate to ask me anything. Thanks! Franz