geotiff.js icon indicating copy to clipboard operation
geotiff.js copied to clipboard

Failed to import geotiff in vue project

Open dongli opened this issue 4 years ago • 9 comments

I have import GeoTIFF from 'geotiff' in a vue file, and run npm run dev with the following error:

 error  in ./node_modules/geotiff/src/geotiff.js

Module parse failed: Unexpected token (283:35)
You may need an appropriate loader to handle this file type.
|     }
|
|     return usedImage.readRasters({ ...options, window: wnd });
|   }
| }

 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/layers/Basemap.vue 9:0-30
 @ ./src/components/layers/Basemap.vue
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

dongli avatar Jul 04 '20 14:07 dongli

Hi @dongli

Thanks for reporting this issue.

The reason for this error seems to be, that geotiff.js uses language constructs that are quite new, such as object property spreading, that not all JavaScript processors understand.

I think there are multiple solutions to this issue. When you want to directly use the source code you can add a language transpiler to your toolchain. I think the most popular one is babel.js. I'm sure that there is an integration for Vue.

The other solution is to use the supplied build output, to be found in the dist-browser directory, which is built upon installation.

@PacoDu with the new Parcel-based build system, what would you propose to use?

constantinius avatar Jul 06 '20 07:07 constantinius

Hi @dongli Which version of geotiffjs and vueJS are you using ? Can you provide an example on how to reproduce the issue ? (codesandbox or a git repo)

PacoDu avatar Jul 06 '20 15:07 PacoDu

Thank you for replying! @PacoDu The version of vuejs is 2.5.2, and geotiffjs is the latest one. Sorry, I am not a JS veteran, I have changed the technique to use PNG directly for the time being.

dongli avatar Jul 11 '20 10:07 dongli

I've not dug into this is any detail - but will note:

I just upgraded from 1.0.0-beta.7 to 1.0.0-beta.13, and my imports stopped working (in both rollup and webpack). What currently works for me:

import * as GeoTIFF from 'geotiff/dist-browser/geotiff';

danwild avatar Jul 20 '20 04:07 danwild

I have the same problem, and I tried the babel.js but it didn't work for me.The version of vuejs is 2.9.6,is there any other way to solve this problem?

zuoxy1997 avatar Aug 08 '20 07:08 zuoxy1997

Same problem here.

muety avatar Jan 31 '22 11:01 muety

@muety This could be fixed with release v2.0.4.

constantinius avatar Feb 03 '22 14:02 constantinius

I'm trying to install stable version of Opelayers 6.13.0 and I'm having the same issue as this depends on geotiff. It currently installs [email protected] and still gives the same error: ERROR in ./node_modules/geotiff/dist-module/geotiff.js Module parse failed: Unexpected token (276:35) You may need an appropriate loader to handle this file type. | } | | return usedImage.readRasters({ ...options, window: wnd }); | } | }

Daniel-Brosnan-Blazquez avatar Mar 02 '22 13:03 Daniel-Brosnan-Blazquez

Did you solve the same issue? @Daniel-Brosnan-Blazquez !! I am facing the same issue with openlayer 6.14.1 ../node_modules/geotiff/dist-module/geotiff.js Module parse failed: Unexpected token (277:35) You may need an appropriate loader to handle this file type. | } | | return usedImage.readRasters({ ...options, window: wnd }); | } | }

Saeed-ul-haq avatar Jun 06 '22 06:06 Saeed-ul-haq