You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bundle with browserify in terminal node node_modules/browserify/bin/cmd.js --entry src/main.js --outfile dist/build.js
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".
Reacted by Franz, Molly Lloyd, chapani and emakarov
changed the title [-]browserify bundling mapbox-gl causes error "Cannot find module './feature' ..."[/-][+]browserify bundle is broken[/+]on Mar 20, 2017
@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.
Ah, I think I misread that browser-pack issue -- it's about the --requireflag -- 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.
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');.
@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
Activity
mollymerp commentedon Mar 20, 2017
We recently switched to exporting the
distfiles for bundlers (#4423) – I've opened a PR to update the docs! #4458mollymerp commentedon Mar 20, 2017
Oops, although our docs were out of date, that doesn't seem to be the issue here.
ellvtr commentedon 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.
[-]browserify bundling mapbox-gl causes error "Cannot find module './feature' ..."[/-][+]browserify bundle is broken[/+]anandthakker commentedon Mar 20, 2017
Thanks for posting the workaround, @ellvtr
@mollymerp I think you're right that this is a result of #4423 -- the
dist/mapbox-gl.jsfile is a bundle built withbrowserify --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 commentedon Mar 20, 2017
Ah, I think I misread that browser-pack issue -- it's about the
--requireflag -- 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 commentedon 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 commentedon Mar 21, 2017
@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