Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for windows platform dependent modules resolution #3606

Closed
wants to merge 2 commits into from

Conversation

nixoz
Copy link

@nixoz nixoz commented May 19, 2017

Summary

According to this issue: facebook/react-native#14053 here is the problems with windows platform dependent modules...

Test plan

copy/paste from the referenced issue for convenience:

Description

If react-native and react-native-windows installed together - the modules from latter considered being generic(g) by the packager(jest-haste-map). As result, we have broken app.

the initial discussion was started here: facebook/react-native#13925

Reproduction Steps and Sample Code

  1. react-native init test
  2. cd test && yarn add react-native-windows
  3. in the generated index.ios.js make a small modification so the render method of default exported component will look like that:
render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          <Text style={styles.instructions}>
            To get started, edit index.ios.js
          </Text>
        </Text>
      </View>
    );
  }
  1. react-native run-ios
  2. ㅠㅠ

2017-05-19 16 10 22

Solution

During investigating this, read a lot of code and eventually come to jest-haste-map - the one which required by react-native.

In the react-native packager defaults.js here is platforms array exported, looks like dat:

exports.platforms = ['ios', 'android', 'windows', 'web'];

at the same time, in jest-haste-map's lib/getPlatformExtension.js we have:

const SUPPORTED_PLATFORM_EXTS = {
  android: true,
  ios: true,
  native: true,
  web: true };

adding windows: true, to SUPPORTED_PLATFORM_EXTS dict will give us a fix:

2017-05-19 16 30 54

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions.

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@cpojer
Copy link
Member

cpojer commented May 24, 2017

You can configure the "haste" config option to add "platforms" manually:

"haste": {
  "platforms": […]
}

that should work for you, no?

@bd
Copy link

bd commented May 31, 2017

@cpojer @nixoz I added

"haste": {
      "defaultPlatform": "ios",
      "platforms": [
        "android",
        "ios",
        "native",
        "windows"
      ],
      "providesModuleNodeModules": [
        "react-native"
      ]
    }

to my applications package.json's jest object, and have stopped getting the RCTVirtualText error. I do still see warnings along the lines of jest-haste-map: @providesModule naming collision: Duplicate module name: <various> ...

@nixoz
Copy link
Author

nixoz commented Jun 1, 2017

@cpojer i've tried that initially, didn't helped me for some reason...
feel free to reject if u think here is no point having it...

But this is something worth having in documentation maybe?

UPD: Just tried again having this in package.json:
(just thought maybe forgot to clear the cache or something)

{
	"name": "test",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"start": "node node_modules/react-native/local-cli/cli.js start",
		"test": "jest"
	},
	"dependencies": {
		"node-inspector": "^1.1.1",
		"react": "16.0.0-alpha.6",
		"react-native": "0.44.0",
		"react-native-windows": "^0.43.0-rc.0"
	},
	"devDependencies": {
		"babel-jest": "20.0.3",
		"babel-preset-react-native": "1.9.2",
		"jest": "20.0.3",
		"react-test-renderer": "16.0.0-alpha.6"
	},
	"jest": {
		"preset": "react-native",
		"haste": {
      "defaultPlatform": "ios",
      "platforms": [
        "android",
        "ios",
        "native",
        "windows"
      ],
      "providesModuleNodeModules": [
        "react-native"
      ]
    }
	}
}
> watchman watch-del-all && npm cache clean && react-native start --reset-cache

Got RCTVirtualText Exception

patched the getPlatformExtension.js, launched again with the same line

Work fine...

@nixoz
Copy link
Author

nixoz commented Jun 1, 2017

@bd, have you tried to build your app with Release configuration? Is it fine?

@cpojer cpojer closed this Jun 6, 2017
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants