rimiti / react-native-toastify

:iphone: React Native cross-plateform (iOS / Android) Toast component highly customizable.
MIT License
33 stars 9 forks source link

Expo - Duplicate module name: react-native #11

Closed appjitsu closed 4 years ago

appjitsu commented 5 years ago

Paths: /Users/user/myapp/app/node_modules/@rimiti/react-native-toastify/node_modules/react-native/package.json collides with /Users/user/myapp/app/node_modules/react-native/package.json

$ expo diagnostics

  Expo CLI 2.21.2 environment info:
    System:
      OS: macOS 10.14.5
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
      Yarn: 1.16.0 - ~/.yarn/bin/yarn
      npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    IDEs:
      Android Studio: 3.4 AI-183.6156.11.34.5522156
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      expo: ^33.0.0 => 33.0.7 
      react: 16.8.3 => 16.8.3 
      react-native: https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz => 0.59.8 
      react-navigation: ^3.3.0 => 3.11.0 
    npmGlobalPackages:
      expo-cli: 2.21.2
"dependencies": {
    "@expo/vector-icons": "^9.0.0",
    "@rimiti/react-native-toastify": "^1.2.0",
    "axios": "^0.18.0",
    "expo": "^33.0.0",
    "expo-linear-gradient": "~5.0.1",
    "formik": "^1.5.1",
    "lodash": "^4.17.11",
    "metro-react-native-babel-preset": "^0.52.0",
    "moment": "^2.24.0",
    "react": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
    "react-native-datepicker": "^1.7.2",
    "react-native-dotenv": "^0.2.0",
    "react-native-elements": "^1.1.0",
    "react-native-modal-selector": "^1.0.3",
    "react-navigation": "^3.3.0",
    "styled-components": "^4.1.3",
    "yup": "^0.26.10"
  },
$ expo publish                             
Unable to find an existing Expo CLI instance for this directory, starting a new one...
Starting Metro Bundler on port 19001.
Tunnel ready.
Publishing to channel 'default'...
(node:4924) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
  Duplicate module name: react-native
  Paths: /Users/user/myapp/app/node_modules/@rimiti/react-native-toastify/node_modules/react-native/package.json collides with /Users/user/myapp/app/node_modules/react-native/package.json

This error is caused by `hasteImpl` returning the same name for different files.
    at setModule (/Users/user/myapp/app/node_modules/jest-haste-map/build/index.js:569:17)
    at workerReply (/Users/user/myapp/app/node_modules/jest-haste-map/build/index.js:641:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4924) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:4924) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:4924) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
  Duplicate module name: react-native
  **Paths: /Users/user/myapp/app/node_modules/@rimiti/react-native-toastify/node_modules/react-native/package.json collides with /Users/user/myapp/app/node_modules/react-native/package.json**

This error is caused by `hasteImpl` returning the same name for different files.
    at setModule (/Users/user/myapp/app/node_modules/jest-haste-map/build/index.js:569:17)
    at workerReply (/Users/user/myapp/app/node_modules/jest-haste-map/build/index.js:641:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4924) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)

Building iOS bundle
Error: jest-haste-map: Haste module naming collision:
  Duplicate module name: react-native
  Paths: /Users/user/myapp/app/node_modules/@rimiti/react-native-toastify/node_modules/react-native/package.json collides with /Users/user/myapp/app/node_modules/react-native/package.json

This error is caused by `hasteImpl` returning the same name for different files.
    at setModule (/Users/user/myapp/app/node_modules/jest-haste-map/build/index.js:569:17)
    at workerReply (/Users/user/myapp/app/node_modules/jest-haste-map/build/index.js:641:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
rimiti commented 5 years ago

Hello @appjitsu ,

Do you still have this error ? Did you try to update RN ?

ronkot commented 4 years ago

I have different problem but I believe the root cause is the same. The problem is that react-native-toastify includes all react and react-native stuff as direct dependencies. How this should be done is through peer dependencies instead.

I think package.json of this library should look something like this:

"dependencies": {
    "prop-types": "15.x"
  },
"peerDependencies": {
    "react": "16.x",
    "react-dom": "16.x",
    "react-native": ">= 0.56 < 1" (or whichever is the minimum version)
}

The tricky part is to find out best possible versions for the peer dependencies. The ones that are least restrictive are best rules.

You can verify that the current configuration causes real problems by initiating a fresh RN project with latest RN version and adding react-native-toastify as a dependency - a red box will appear on the emulator.

rimiti commented 4 years ago

Hello @ronkot ,

Could you please test this @rimiti/react-native-toastify@1.2.2-0 version and let me know if it's now ok. 🙏

rimiti commented 4 years ago

I confirm you that's working well:

image

ronkot commented 4 years ago

Nice, super speed fix 😄 🎉

Using exact version numbers as a peer dependency will cause version mismtach warnings for most users, but it should not affect the behavior. If you want to refine the fix further, just use peer dependency version range as I suggested in https://github.com/rimiti/react-native-toastify/issues/11#issuecomment-668392449.

Anyway, super work. Thanks for this library! 💪

rimiti commented 4 years ago

Aha!

Thanks for your contribution 🙏

New PR related to your last comment. #20