geotiffjs / geotiff.js

geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.
https://geotiffjs.github.io/
MIT License
880 stars 184 forks source link

Unable to resolve module "geotiff" when importing in React native #126

Open JoBerkner opened 4 years ago

JoBerkner commented 4 years ago

I think this issue is more React Native related, but perhaps somebody knows how to solve this. I am building a React Native app using Expo and installed geotiff using:

npm install geotiff --save

However, when I try to import it in my React Native project:

import GeoTIFF from 'geotiff'

I am getting the error:

The development server returned response error code: 500 [...] Unable to resolve module "geotiff" from "{path to component}": geotiff could not be found within the project.

However, when trying to get it from command line it works:

> node
> const GeoTIFF = require('geotiff')
> GeoTIFF
{ GeoTIFF: [Getter],
  MultiGeoTIFF: [Getter],
  fromUrl: [Getter],
  fromArrayBuffer: [Getter],
  fromFile: [Getter],
  fromBlob: [Getter],
  fromUrls: [Getter],
  Pool: [Getter] }

Does anybody know how to resolve this? I tried the solution that was provided in #46, but it did not change anything.

46

constantinius commented 4 years ago

Unfortunately I do not have any experience with React Native or Expo. Typically the bundlers find the library or can be tweaked to find it.

philip-firstorder commented 4 years ago

With "geotiff": "1.0.0-beta.10" I have the same problem in Angular 9, but fixed it by importing like this:

import * as GeoTiff from 'geotiff';

I also get this warning when compiling for Angular Universal for SSR, could be related:

WARNING in ./node_modules/geotiff/dist-browser/main.js 1:292-296
Critical dependency: the request of a dependency is an expression
PacoDu commented 4 years ago

I also get this warning when compiling for Angular Universal for SSR, could be related:

WARNING in ./node_modules/geotiff/dist-browser/main.js 1:292-296
Critical dependency: the request of a dependency is an expression

This is due to the browser field in package.json that I've added in #131. It is not properly defined and should be fixed by #144.

Can you tell me if the PR fixes the issue for you Angular build ? Note that you need to add the threads-plugin to your webpack config if you are using GeoTIFF.Pool (see: https://github.com/geotiffjs/geotiff.js/pull/144/files#diff-04c6e90faac2675aa89e2176d2eec7d8R301-R315).

It may also fixes the import issue depending on the configuration of your project.

constantinius commented 4 years ago

@JoBerkner @PacoDu do you think we can close this issue now? (I'm not a React native user)

JoBerkner commented 4 years ago

@constantinius yes, I think the solution provided by @philip-firstorder works (did not test it though, but I know of an exact same issue with another library in React Native). I will test it today one .ore time once I am on my PC.

jsbroks commented 4 years ago

Im getting compile errors on nuxtjs, not sure if related


 ERROR  Failed to compile with 2 errors                                                                          friendly-errors 21:52:42

This dependency was not found:                                                                                   friendly-errors 21:52:42
                                                                                                                 friendly-errors 21:52:42
* fs in ./node_modules/geotiff/src/source.js, ./node_modules/txml/tXml.js                                        friendly-errors 21:52:42
                                                                                                                 friendly-errors 21:52:42
To install it, you can run: npm install --save fs                                                                friendly-errors 21:52:42
``
MatheusRBarbosa commented 11 months ago

I'm with the same issue with nextjs 14. I already tried the @philip-firstorder solution and it not worked =(