-
Notifications
You must be signed in to change notification settings - Fork 184
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
Can't resolve 'fs' in dist #98
Comments
Hi @Ilheu This only fixes the problem when you are using webpack to bundle your application. Maybe you can share your full webpack configuration and versions, to maybe find a solution. |
I agree with @constantinius . Happy to help resolve this issue with you if you share a sample of your configuration and versions :-) |
Hi, thank you for the quick answer ! My webpack configuration is this one :
Is this what you asked ? Or need something more ? |
What are you using to bundle your Angular Application? If you are using webpack, could you provide the webpack configuration for your Angular application? Thanks! |
Hi @DanielJDufour , I am using angular 8 and I used angular cli to create my app. I read that the webpack config is hidden ... Do you think that this could be the problem ? Should I do this (https://blog.angularindepth.com/customizing-angular-cli-build-an-alternative-to-ng-eject-v2-c655768b48cc) do customize the webpack ?! |
My main objective with your software, is to get coordinates from a tiff image so I can put an image on an openlayers' map. Is there any easier way ? |
Option 1 Here's some other somewhat inferior workarounds: Option 2 <script src="https://unpkg.com/geotiff@1.0.0-beta.6/dist/geotiff.bundle.min.js"></script> And then later on access it through the global window.GeoTIFF Option 3 Option 4 Hope this helps and let me know how it goes! |
@DanielJDufour Thanks for the availability and help. |
Hi @DanielJDufour , I've been reading some stuff and I think I had a wrong notion of how to do what I want ... I have several .tiff format images. I wanted to show these images at their coordinates on the front end using angular 8. I was just wondering if I could just ask the images to my backend via a request get and overlay on the openlayers map, can I do it this way? or need to use a server for sharing geospatial data like mapserver or geoserver ? |
@Ilheu if you have your images available somewhere public (behind a URL) you can try to use the COG explorer and enter the URL to load them. This should display the image at the correct coordinates. |
I also receive this error on Angular 8, tried #51 but it didn't solve the issue. |
@Ilheu How did you manage to solve the error on Angular 8. |
I did not solved it yet, this project is in stand by ... I'm still trying to find a solution that fits in. |
I managed to find 2 simple solutions that both work:
import { fromUrl } from 'geotiff/dist/geotiff.bundle.min.js';
fromUrl('yourtiff')
.then(tiff => {
// ...
}); Either solution can serve, build, ssr and prerender Angular Universal. I tried a lot of other things that didn't work like:
"browser" {
"fs": false
}
node: {
fs: 'empty'
} @constantinius Since Angular 6 they don't support Electron anymore, I guess you have to add a check for the node environment when importing 'fs', but I am not familiar enough with this to help you with a pull request. |
Tested with latest changes: https://github.com/PacoDu/geotiff.js.git#change-main-entrypoint The problem is that './source.js' is included in "dist-browser/" with these 3 lines: Lines 2 to 4 in 2ea5af8
A workaround until now was to add these lines to package.json in our own projects, but this is NOT the proper solution. "browser": {
"fs": false,
"http": false,
"https": false
}, Instead a browser check needs to be done by geotiff.js so that we don't get this errors anymore when using the library. |
I agree with the addition of the browser field to Also, I think we need to understand better why angular SSR build is using the main entry point to resolve the imports and then uses the |
It resolves to |
Thanks @PacoDu for pointing out the browser field in the package json, I just published version 3.1.3. |
I had the same problem but I resolved it with the solution @philip-firstorder mentioned. But I need to use pool to open big tiffs, on the line `GET http://localhost:4200/decoder.worker.js 404 (Not Found) 39core.js:6210 ERROR Error: Timeout: Did not receive an init message from worker after 10000ms. Make sure the worker calls expose(). I guess the problem is that I need to install threads-plugin, but I don't know how to use it on angular |
With v.1.0.4 I still get the following errors:
import { fromUrl, fromUrls, Pool } from 'geotiff/dist-browser/geotiff'; ./node_modules/geotiff/dist-browser/geotiff.js:1:292-296 - Warning: Critical dependency: the request of a dependency is an expression
import { fromUrl, fromUrls, Pool } from 'geotiff'; // as described in the README.md
import * as GeoTIFF from 'geotiff';
import GeoTIFF from 'geotiff'; ./node_modules/geotiff/src/source/client/http.js:1:0-24 - Error: Module not found: Error: Can't resolve 'http' in '/Users/philip/Projects/FairFleet/ff3-fe/node_modules/geotiff/src/source/client'
Did you mean './http'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (/Users/philip/Projects/FairFleet/ff3-fe, node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }
./node_modules/geotiff/src/source/client/http.js:2:0-26 - Error: Module not found: Error: Can't resolve 'https' in '/Users/philip/Projects/FairFleet/ff3-fe/node_modules/geotiff/src/source/client'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }
./node_modules/geotiff/src/source/file.js:1:0-39 - Error: Module not found: Error: Can't resolve 'fs' in '/Users/philip/Projects/FairFleet/ff3-fe/node_modules/geotiff/src/source' So even after 2 years this is still a time consuming problem for us, a fix is needed and I would gladly be available to test on the latest angular 12. |
Thanks @philip-firstorder for this update. I just installed the lib via npm and got the same issue you mentioned. But in my case while Any ideas and / or solutions? |
Hi,
I installed geotiff with "npm i geotiff --save", and I keep getting the following error:
I've seen this issue ( #51) but it hasn't fixed my problem ... The webpack has
The text was updated successfully, but these errors were encountered: