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 react-native example project #890

Closed
wants to merge 1 commit into from

Conversation

garfieldnate
Copy link
Contributor

The default plugin for validation, is-my-json-valid, depends on
generate-functions, which uses core Node libraries and is therefore not usable
outside of the Node environment. Attempting to build the project before led
to the following error:

Unable to resolve module `util` from `<workspace/node_modules/generate_function/index.js`: Module `util` does not exist in the Haste module map

The solution to this is to use AJV for validation instead, which requires using custom
build logic to determine which plugins are loaded.

Also added try/catch around await statements, since that was the only way I
could find this problem in the first place.

This PR contains:

bug fix; I have not included a test because the project would not build at all before.
Just building the project is the test :)

Todos

Although I only aimed to fix the react-native project in this PR, other non-node
environments will have the same problem. It would probably be better to provide
a built-in default plugin bundle for non-node environments.

This problem for non-node environments should probably be documented somewhere;
to me the preferable alternative would be to make AJV the default validation and tell
users that they can speed up performance on Node by using is-my-json-valid instead.
Right now, RxDB may be broken out-of-the-box for many users.

The default plugin for validation, `is-my-json-valid`, depends on
`generate-functions`, which uses core Node libraries and is therefore not usable
outside of the core environment. Attempting the build the project before led
to the following error:

    Unable to resolve module `util` from `<workspace/node_modules/generate_function/index.js`: Module `util` does not exist in the Haste module map

The solution to this is to use AJV for validation instead.

Also added try/catch around await statements, since that was the only way I
could find this problem in the first place.
@garfieldnate
Copy link
Contributor Author

🤦‍♂️ It works on my computer. Without the change, it does not work. I don't know why.

@pubkey
Copy link
Owner

pubkey commented Feb 6, 2019

I'm not sure if this is an rxdb-problem.
The react-native example is in the ci and works, see here
I think we should start by adding something to the CI that shows what is broken.

Does your error appear on build or on runtime?

pubkey added a commit that referenced this pull request Feb 6, 2019
@garfieldnate
Copy link
Contributor Author

Okay, here's what I see:

  • The tests pass. Building as in the instructions and running npm test works and passes just fine.

  • The app will not run if you actually try to start it using the iOS simulator. Do npm start, press i to open the app in the iOS simulator. You will immediately get this error:

      Unable to resolve ../../" from ".//App.js`: The module `../../` could not be found"
    
  • There's a discussion of the above issue here. The solution is to put "rxdb": "file:../../" in the dependencies section of package.json. Then in App.js you change the import line to import RxDB from "rxdb";. I'm not sure how to do fix package.json correctly in this project as it seems that it is written dynamically when the parent project is built. If you could guide me here, I would like to update the PR to fix this.

  • If you manually fix the above issue, then the next error is printed in the terminal:

      Failed building JavaScript bundle
    

and in the simulator you see the following:

Unable to resolve module `util` from `...rxdb/examples/react-native/node_modules/generate-function/index.js`: Module `util` does not exist in the Haste module map or in these directories: `...rxdb/node_modules`

The problem being that util is only available in the node environment, and it is required by is-my-json-valid.

I believe that the problem is that jest runs tests on Node, completely hiding this problem. I feel like that is an annoying problem with the ecosystem, but I don't know any way to fix it with just jest. The only way I can think of to fix the erroneously-passing test suite is to add an actual end-to-end test using something like Detox or Cavy. The tests need to actually start up a simulator and load the app to show this error.

@garfieldnate
Copy link
Contributor Author

I was going to begin work on a Detox test for this, since that project has documentation on running with Expo and with travis-CI, but I couldn't even build T_T. I filed wix/Detox#1145 and await a fix before I can use the tool.

pubkey added a commit that referenced this pull request Feb 6, 2019
pubkey added a commit that referenced this pull request Feb 6, 2019
@pubkey
Copy link
Owner

pubkey commented Feb 6, 2019

I could reproduce this problem locally. I am now looking into how to lets this fail the CI so I can ensure the problem will never reapear

pubkey added a commit that referenced this pull request Feb 6, 2019
@pubkey pubkey closed this in 3b0b272 Feb 7, 2019
@pubkey
Copy link
Owner

pubkey commented Feb 7, 2019

I could fix this. Please check out the new release.

@garfieldnate
Copy link
Contributor Author

Works great! Thanks!

@garfieldnate garfieldnate deleted the fix-rn-example branch February 8, 2019 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants