basket.js icon indicating copy to clipboard operation
basket.js copied to clipboard

Uncaught ReferenceError: basket is not defined

Open mzhangx opened this issue 9 years ago • 1 comments

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?

mzhangx avatar Jan 06 '17 20:01 mzhangx

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

karlicoss avatar Nov 05 '20 19:11 karlicoss