question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems importing leaflet.glify with react

See original GitHub issue

Hello guys I’m having this error when I import ‘leaflet.glify’ package:

TypeError: fs.readFileSync is not a function (anonymous function) C:/Users/leo_c/Documents/projects/leo-gis-web/node_modules/leaflet.glify/src/js/index.js:212 209 | }, 210 | mapMatrix: mapMatrix, 211 | shader: { 212 | vertex: fs.readFileSync(__dirname + ‘/…/shader/vertex/default.glsl’), | ^ 213 | fragment: { 214 | dot: fs.readFileSync(__dirname + ‘/…/shader/fragment/dot.glsl’), 215 | point: fs.readFileSync(__dirname + ‘/…/shader/fragment/point.glsl’), View compiled ./node_modules/leaflet.glify/src/js/index.js http://localhost:3000/static/js/1.chunk.js:8881:30 webpack_require C:/Users/leo_c/Documents/projects/leo-gis-web/webpack/bootstrap:785 782 | }; 783 | 784 | // Execute the module function 785 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId)); | ^ 786 | 787 | // Flag the module as loaded 788 | module.l = true; View compiled fn

my code importing it: import 'leaflet.glify';

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mathieugallecommented, Mar 24, 2020

Hi,

I have no experience with the React part of your problem so this may not work for you, but here’s how I managed to get rid of the fs problem and import leaflet.glify with webpack :

  • npm install leaflet.glify (obviously)
  • Go to the file node_modules/leaflet.glify/src/js/index.js
  • delete the first line var fs = require('fs');
  • go at the end of the file, you will find all the usages of fs, like vertex: fs.readFileSync(__dirname + '/../shader/vertex/default.glsl'). It is just used to import the shaders
  • remove references to fs and copy-paste the content of the shader instead (between `` quotes) for shaders you use. For example, as I only used points, I copy-pasted vertex/default.glsl and fragments/point.glsl, and leaved the rest as ``

This is obviously a hack, but the fs library here is brfs which is a browserify dependency. You can also check on webpack-contrib , webpack tools to allow browserify transforms, but for a few shaders, I think it’s not really worth the pain.

In the long run, I hope that it will be possible to remove the dependency to brfs and go for something like glslify-require instead, like done here.

Hope this works for you !

0reactions
leodavinci1commented, Mar 30, 2020

I have encoded the shader into a base64 string,

vertex: Buffer("dW5pZm9ybS ... yOwp9", "base64")

Definitely a hack but fixed my problem developing with react.

Read more comments on GitHub >

github_iconTop Results From Across the Web

robertleeplummerjr/Leaflet.glify - GitHub
web gl renderer plugin for leaflet in typescript ... import glify from 'leaflet.glify'; ... CAUTION: May cause performance issue with large data sets....
Read more >
leaflet.glify - npm
Start using leaflet.glify in your project by running `npm i leaflet.glify`. There are no other projects in the npm registry using leaflet.glify.
Read more >
react-leaflet map not correctly displayed - Stack Overflow
1. react-leaflet package · 2. Leaflet package: Either, install it using npm. npm install leaflet and import 'leaflet/dist/leaflet.css'; in the file where you...
Read more >
Plugins - Leaflet - a JavaScript library for interactive maps
A Leaflet TileLayer which can modify colors by RGBA code. A Leaflet TileLayer with getColor(latLng). Applies custom WebGL shaders to each tile in...
Read more >
How to render huge GeoJSON datasets on a map (part 2).
glify is a very powerful plugin, but does have some downsides. To address these issues I setup a peer leaflet plugin called Leaflet.glify.layer, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found