question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-native build error on import

See original GitHub issue

I reproduced this from a new npx react-native init reproProj. Note that android studio, sdk and emulator are prerequisite to the init command and then launching reproProj with npm run android.

I’m not too familiar with the build environment for react-native but anyhow taking the following steps with reproProj

  1. npm i -S --no-optional sanctuary
  2. add import * as S from 'sanctuary' to the generated App.js
  3. npm run android

I get:

    at ModuleResolver.resolveDependency (D:\src\reproProj\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:186:15)
    at ResolutionRequest.resolveDependency (D:\src\reproProj\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (D:\src\reproProj\node_modules\metro\src\node-haste\DependencyGraph.js:287:16)
    at Object.resolve (D:\src\reproProj\node_modules\metro\src\lib\transformHelpers.js:267:42)
    at D:\src\reproProj\node_modules\metro\src\DeltaBundler\traverseDependencies.js:434:31
    at Array.map (<anonymous>)
    at resolveDependencies (D:\src\reproProj\node_modules\metro\src\DeltaBundler\traverseDependencies.js:431:18)
    at D:\src\reproProj\node_modules\metro\src\DeltaBundler\traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (D:\src\reproProj\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)
[Wed Oct 07 2020 19:04:00.925]  BUNDLE  ./index.js

error: Error: Unable to resolve module `util` from `node_modules\sanctuary-def\index.js`: util could not be found within the project.

The above workflow works fine for other npm libs such as ramda or redux.

npx react-native --version is 4.13.0 metro: 0.58.0, metro-core at 0.58.0, sanctuary at 3.1.0 sanctuary-def at 0.22.0

I’m not familiar with the usage of require where util is set up but I gather that it is not specifying that a js file be resolved. Perhaps “metro node-haste” misinterprets the require usage in a similar way.

Edit - I tried updating metro to their latest release 0.63.0 but that seems to have broken something in the otherwise as generated app/build.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
llaenowydcommented, Apr 13, 2021

Not at this time! Thanks for your contributions to the development of functional techniques in Javascript!

1reaction
davidchamberscommented, Apr 13, 2021

It’s not clear to me whether there is something I could change to make Sanctuary work better for you, @llaenowyd. Let me know if there is. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is importing not working in react native? - Stack Overflow
If file to import is not .js, then make sure appropriate react library is imported in first import E.g.( import {..., Image }...
Read more >
Troubleshooting common React Native bugs - LogRocket Blog
Import error. Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite ...
Read more >
Troubleshooting - React Native
If you encounter an error such as npm WARN locking Error: EACCES while using the React Native CLI, try running the following:.
Read more >
Code-Splitting - React
Once you've created your Error Boundary, you can use it anywhere above your lazy components to display an error state when there's a...
Read more >
Troubleshooting | React Navigation
This and some similar errors might occur if you have a bare React Native project and the library react-native-safe-area-context library isn't linked. Linking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found