Skip to content
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

browserify bundle is broken #4453

Closed
ellvtr opened this issue Mar 20, 2017 · 7 comments
Closed

browserify bundle is broken #4453

ellvtr opened this issue Mar 20, 2017 · 7 comments

Comments

@ellvtr
Copy link

ellvtr commented Mar 20, 2017

mapbox-gl-js version: "^0.34.0"

Steps to Trigger Behavior

Complete reproduction of bug in this super simple dedicated repo:
https://github.com/awesomemaptools/mbtst

  1. Require module with require('mapbox-gl/dist/mapbox-gl') as documented here: https://www.mapbox.com/mapbox-gl-js/api/
  2. Initiate map in main.js
  3. Bundle with browserify in terminal
    node node_modules/browserify/bin/cmd.js --entry src/main.js --outfile dist/build.js
  4. Terminal outputs:
Error: Cannot find module './feature' from '.../mbtst/node_modules/mapbox-gl/dist'
    at /home/jonas/zegeba/repos/mbtst/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21
    at load (/home/jonas/zegeba/repos/mbtst/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
    at onex (/home/jonas/zegeba/repos/mbtst/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
    at /home/jonas/zegeba/repos/mbtst/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:123:15)

Expected Behavior

Expected to create bundle in dist/build.js and when run in browser, map will render as it does using regular CDN.

Actual Behavior

Terminal error - "Cannot find module".

@mollymerp
Copy link
Contributor

We recently switched to exporting the dist files for bundlers (#4423) – I've opened a PR to update the docs! #4458

@mollymerp
Copy link
Contributor

Oops, although our docs were out of date, that doesn't seem to be the issue here.

@mollymerp mollymerp reopened this Mar 20, 2017
@ellvtr
Copy link
Author

ellvtr commented Mar 20, 2017

After I isolated the issue in the small repo, I made it work when requiring from source:
require('mapbox-gl/src/index.js');
See https://github.com/awesomemaptools/mbtst
Still doesn't work from dist, though.

@mollymerp mollymerp changed the title browserify bundling mapbox-gl causes error "Cannot find module './feature' ..." browserify bundle is broken Mar 20, 2017
@anandthakker
Copy link
Contributor

Thanks for posting the workaround, @ellvtr

@mollymerp I think you're right that this is a result of #4423 -- the dist/mapbox-gl.js file is a bundle built with browserify --standalone mapboxgl. (See #4453 and #4391 as well.)

browserify/browser-pack#45 suggests that standalone browserify bundles might not be usable as modules that can be require()'ed and re-browserified.

@anandthakker
Copy link
Contributor

Ah, I think I misread that browser-pack issue -- it's about the --require flag -- but nonetheless, it does seem like the issue here is requiring the standalone browserified bundle as if it were a 'normal' node module, and then browserifying.

@ellvtr
Copy link
Author

ellvtr commented Mar 21, 2017

I see that you changed the docs to const mapboxgl = require('mapbox-gl') which still produces the same error. I guess you also changed main in package.json to point to "dist/mapbox-gl.js"?
It still works with var mapboxgl = require('mapbox-gl/src/index.js');.

@anandthakker
Copy link
Contributor

@ellvtr yes--please proceed with require('mapbox-gl/src/index.js') for now. We're working to fix this, hopefully for both browserify and webpack this time, over in #4462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants