calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
MIT License
737 stars 230 forks source link

./node_modules/shpjs/lib/unzip.js Module not found: Can't resolve 'but-unzip' in '<myfolder>/node_modules/shpjs/lib' #217

Open ahalota opened 16 hours ago

ahalota commented 16 hours ago

I have a create-react-app application. I tried to install this via yarn add shpjs It downloaded the files, and dependencies correctly. It seems something is wrong with the module resolution though, when I try to run my code it won't compile and gives this error (where "myfolder" is a valid location). I do have but-unzip in my node_modules folder, it came with this package's dependencies.

./node_modules/shpjs/lib/unzip.js Module not found: Can't resolve 'but-unzip' in '<myfolder>/node_modules/shpjs/lib'

Appreciate any ideas on how to resolve this. Thanks!

calvinmetcalf commented 15 hours ago

so you've added import shp from 'shpjs'; to your app somewhere and when you run yard start it gives you that error?

ahalota commented 14 hours ago

Hm. I wish I could say more clearly what's happening when I run my site...I assume(?) create-react-app does some sort of magic which includes a compiling step, and it's at that step that I am getting this error.

Fails to compile because it can't find the module in <..>/node_modules/shpjs/lib, which is appropriate, since I don't have the library there, but instead in in <..>/node_modules/but-unzip/...

Which is my best guess was that something in @rollup/plugin-node-resolve wasn't acting the way I wanted

calvinmetcalf commented 14 hours ago

the file dist/shp.esm.js is a compiled single file version of this library containing all it's dependencies appropriate to import into an app. You may just find it easier to copy that file into your code base so you can just do import shp from '../vendor/shp.esm.js' or something .

ahalota commented 13 hours ago

From some debugging my best theory right now is that the way we have create-react-app configured, it does not play nicely with dual-export libraries (which offer the esm/commonjs exports).

I'm going to do the direct import of the file and most likely try to get off of CRA for the future. If anyone has gotten this library to successfully load into a CRA project, please comment, thanks

calvinmetcalf commented 13 hours ago

I've switched from create-react-app to vite and have found it to be an improvement, create-react-app is fine until you have to do anything that strays from it's garden path even a little, and then it falls apart.