basket.js
basket.js copied to clipboard
Uncaught ReferenceError: basket is not defined
I am trying to use basket.js in one of my client side projects and seeing the following errors in console after bundling the app in webpack.
Importing the module on top of the app.
import basketjs from 'basket.js';
console.log(basketjs);
Building the above 2 lines test application.
npm run build:dev
Error message in console
Uncaught ReferenceError: basket is not defined
at application_bundle.js:356
at Object.<anonymous> (application_bundle.js:358)
at __webpack_require__ (application_bundle.js:30)
at Object.<anonymous> (application_bundle.js:73)
at __webpack_require__ (application_bundle.js:30)
at Object.<anonymous> (application_bundle.js:62)
at __webpack_require__ (application_bundle.js:30)
at application_bundle.js:50
at application_bundle.js:53
at webpackUniversalModuleDefinition (application_bundle.js:7)
Why?
The problem is that the basket variable(dependency) can't be found by webpack, it requests to be defined in advanced of implementation.
Solution
Updating line 204 to the following code snippet, so the rest basket.something can be successfully invoked.
var basket = window.basket = {
....
May I submit a PR?
If someone else has the same problem, and would like to use the NPM version instead of maintaining their own fork, here's how you can patch it with webpack: https://github.com/karlicoss/promnesia/commit/de5ae3a21adc84ce61ce5e1e67284709007934ba