globalize: Bundling with Webpack doesn't work well

congrats on 1.0! been waiting a long time to use the shiney new globalize 😃

I have been running into issues using Globalize with webpack ( browserify may suffer similarly).

ERROR in ./~/globalize/dist/globalize/number.js
Module not found: Error: Cannot resolve module 'cldr' in \node_modules\globalize\dist\globalize

Investigation shows that this is due to the AMD check running first in the UMD wrapper for the files, since the package has been installed from npm there is no cldr package for webpack to find. there is a cldrjs however and if I tell webpack to ignore amd style modules for globalize it works just fine.

The problem is that as a library author using Globalize and publishing to npm I can’t ask consumers of my module to add a special exemption to there build process in order to get my module to load. I am not sure what the best way to ā€œfixā€ this is other then building a commonjs (or amd) only version of globalize that gets published to npm, instead of the general /dist build that works for both bower and npm

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 36 (18 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @rxaviers , I’m currently writing a library that depends on globalize but I have no control over consumers’ webpack configs, i.e. globalize-webpack-plugin is not an option. What are my options here?

@JeremyRylan A less brittle solution you can try is to add this loader to your webpack config

{ test: /globalize/, loader: 'imports?define=>false' }

Which will tell Webpack to ignore AMD imports for modules that match globalize packages (untested).

As I say in above posts, this is an ok solution for app developers, but not feasible for building libraries that depend on globalize.

For the most simple repo of the problem: https://gist.github.com/jquense/10e3d57e1ce8ae0467da

If you are looking for a real life use case you can check out https://github.com/jquense/react-widgets which is a component library I maintain that depends on globalize for date and number pickers

Right now to get this to work with 1.0.0 I either need to

  1. bundle all my code up into a monolithic ā€œdistā€ build
  2. Tell my users how to handle building my libraries dependencies

The first is not feasible, as it destroys a lot of the benefits of using modules, and means that users cannot consume my library ala carte. Right now you can do: require('react-widgets/lib/DateTimePicker') if you only want to use the date picker component in an app. Webpack/Browserify will include only the code needed by the date picker, instead of sending all components to a client you only pay for the bytes you use.

Number two is not ideal, but for all the reasons I’ve said earlier.