timekit-io/booking-js

Breaks on CommonJS/Browserified builds

Closed this issue · 3 comments

Since this package is hosted on NPM, developers expect to be able to plug this in to a Browserified or CommonJS build.

[19:11:21] 'bundle:prod' errored after 4.57 s
[19:11:21] Error: Cannot find module 'jQuery' from '/var/www/ng-starter-app/src/node_modules/timekit-booking/dist'
    at /var/www/ng-starter-app/src/node_modules/resolve/lib/async.js:46:17
    at process (/var/www/ng-starter-app/src/node_modules/resolve/lib/async.js:173:43)
    at ondir (/var/www/ng-starter-app/src/node_modules/resolve/lib/async.js:188:17)
    at load (/var/www/ng-starter-app/src/node_modules/resolve/lib/async.js:69:43)
    at onex (/var/www/ng-starter-app/src/node_modules/resolve/lib/async.js:92:31)
    at /var/www/ng-starter-app/src/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:117:15)
[19:11:21] 'build' errored after 4.88 s

This is from NPM-installing your package and importing it in a browserified app.

Since jQuery is a dependency, could you please include in package.json and find a way to make it work with Browserify?

@yangmillstheory I've been trying to get it to work properly with other Browserify/Webpack builds, but I'm having trouble.

As jQuery is registered as an "external" dependency, it's isolated from the bundle and expects a window.jQuery to be available on load. It works fine if we use jQuery from a cdn with the <script> tag, but I can't get it to load if I'm requiting jQuery in a browserify build - event though I set it to window.jQuery = require('jquery') before requiring booking-js.

Not much help to be found in the docs: https://webpack.github.io/docs/library-and-externals.html

Do you have any ideas?

@yangmillstheory I took another stab at it, think It's fixed now. See #118 for details.
If it's still relevant to you, could you give it another shot?

FYI, you still need to provide jquery yourself, but at least it works in a CommonJS build now - just require('jquery') before require('timekit-booking')