Operating System and version (desktop or mobile): All
Context
Using itowns as a dependency causes bundling (e.g. with webpack) and runtime errors due to a missing buffer module. This error comes from shpjs (as well as its dependency safe-buffer) which assumes a node runtime context where Buffer is part of the "standard library".
This causes additional hassle to library users (by definition in a browser context) which:
have bundler/runtime errors on their first use of the library
should add a buffer polyfill in their bundler configuration
By the way, this problem does not arise on our own examples due to a "luck" factor. The buffer polyfill is part of our list of dependencies since puppeteer (from devDependencies) depends on it. You could see it with npm list --all.
Steps to Reproduce (for bugs)
You could reproduce this issue:
creating a new external project by:
setting up a simple npm project using itowns as a dependency.
writing a simple code importing itowns
start it
within the itowns repo by:
removing puppeeteer from devDependencies (see explanation below)
running npm install
running npm start
Expected Behavior
Using itowns as a dependency shall work out-of-the-box and not cause bundling and runtime errors due to buffer.
Actual Behavior
Runtime and bundling errors in projects using itowns
Possible Cause/Fix/Solution
Add the buffer polyfill as part of itowns dependencies.
Your Environment
Context
Using
itowns
as a dependency causes bundling (e.g. with webpack) and runtime errors due to a missingbuffer
module. This error comes fromshpjs
(as well as its dependencysafe-buffer
) which assumes anode
runtime context whereBuffer
is part of the "standard library".This causes additional hassle to library users (by definition in a
browser
context) which:buffer
polyfill in their bundler configurationBy the way, this problem does not arise on our own examples due to a "luck" factor. The
buffer
polyfill is part of our list of dependencies sincepuppeteer
(fromdevDependencies
) depends on it. You could see it withnpm list --all
.Steps to Reproduce (for bugs)
You could reproduce this issue:
npm
project using itowns as a dependency.itowns
puppeeteer
fromdevDependencies
(see explanation below)npm install
npm start
Expected Behavior
Using
itowns
as a dependency shall work out-of-the-box and not cause bundling and runtime errors due tobuffer
.Actual Behavior
Runtime and bundling errors in projects using
itowns
Possible Cause/Fix/Solution
Add the
buffer
polyfill as part of itownsdependencies
.