-
Notifications
You must be signed in to change notification settings - Fork 200
Fix package import for modern frontend #144
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
Conversation
I get this error in Angular 9: |
@PacoDu thanks for following up on this! Webpack allowed to inline workers, is there a similar functionality for parcel as well? Regarding the package.json fields: it seems like the Thanks for testing with so many frameworks, that is good and necessary! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PacoDu thanks for following up on this!
Webpack allowed to inline workers, is there a similar functionality for parcel as well?
No idea, I just use geotiff in Angular 9, I am building now a demo project for you to add in
https://github.com/PacoDu/threads-packageRegarding the package.json fields: it seems like the
browser
field does not work well for webpack, so I guess usingmodule
instead would be fine, but doesn't this conflict with other users of that field?
module
should be okThanks for testing with so many frameworks, that is good and necessary!
Sorry I tested just Angular, but I have used this library for a year now in production with drone COGs
I created an angular universal demo repository for you to reproduce the error and test: To ger the First will install the packages, including your PacoDu:fix-modern-frontend-import fork |
@PacoDu I tested the build in my component library using |
It's not the first time I see this error with this repo, I'm pretty sure it's related to the way @constantinius I don't really see any reason to keep |
I've also introduced a parallel build with |
@philip-firstorder Thanks for providing the test repo. The issue is not related to the one I mentioned above. You used GeoTiff instead of GeoTIFF. |
Well I probably had some cache or link issue with my previous comment, we also need to change the main file to Changing |
Note: This comment assumes that the main entrypoint of geotiff.js is set to @philip-firstorder I did some tests with your repo. What I don't understand is that the ssr build of angular is using the node js entrypoint ... But it is not able to resolve node specific modules like fs, http, https ... You can add the following browser field to your
Also, it is really strange how angular resolves the module: It looks for the module entrypoint to resolve the imports but uses the node entrypoint (main) at some point because webpack emits the following warning at the end:
🤔🤔🤔 The resulting build is probably not optimal due to webpack warning, but it passes. |
I renamed the import from GeoTiff vs GeoTIFF. But still get the error: The only way to get rid of this error was to change line: 86 in "module": "src/geotiff.js", I added these lines in package.js to get rid of the fs, http, https errors. However I don't feel that I have to add these at all. Shouldn't geotiff.js take care to do the proper browser checks? "browser": {
"fs": false,
"http": false,
"https": false
}, As for the warning message I tried adding a browser check in an if clause before creating any GeoTIFF.Pool() instance: pool = typeof window !== 'undefined' ? new GeoTIFF.Pool() : null; But I still get the warning: WARNING in ../geotiff.js/dist-node/main.js 1:292-296
Critical dependency: the request of a dependency is an expression So the current pull request is not yet working in angular. |
Well, regarding this PR I think we are good to go. I can address the main entrypoint issue in another PR and we may need to investigate SSR builds. I'll also do some tests with VueJS SSR. |
<script> | ||
console.log(GeoTIFF); | ||
// Note: GeoTIFF.Pool will not work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that exactly? The worker is not available on jsdelivr? Can we upload/cache just one file there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the worker has its own bundle, and it is not possible to load a worker from a cross-origin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to be able to import the bundle from a CDN maybe it is possible with webpack. I can try to do this in another PR (a revert is not enough as we still need a separate build for NodeJS and browsers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood.
And we still need a bundled version for node, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but it can be achieved with webpack as well.
Closing, merged with #145 |
This PR fixes issues I introduced with #131 :
browser
field frompackage.json
and added themodule
field pointing tosrc/main.js
. Thebrowser
field was misleading builders like webpack that were using the built version of the application (dist-browser
), breaking tree-shaking and imports from src. (see:browser
vsmodule
fields inpackage.json
webpack/webpack#4674 about webpack's package.json fields priority)import 'threads/register'
which was breaking webpack buildsfiles
topackage.json
jsdelivr
topackage.json
for CDN installation and usage of GeoTIFF via the global variablenpm-run-all
I created a repo to do some tests with treads.js packaged in a library: https://github.com/PacoDu/threads-package. I've tested the solution with multiple clients: VueJS, React, NodeJS, raw webpack and raw parcel bundling. It seems to work properly in every cases.
This PR may needs more tests, but it's better than the current version that is not working as expected for modern frontend builds.
Should fix: #143