Error importing sparkjs with webpack/babel-loader

I have a webpack / reactjs project which runs without errors or issues. I’m having some trouble getting sparkjs included in the build. I’ve run

npm install --save spark

Then I’ve built a ParticleService which basically abstracts the spark interface i.e. the following but with a few localStorage calls:

export default class ParticleService {
    Login() { console.log("Logging in"); }
    Logout() { console.log("Logging out"); }

As you can see it currently contains no sparkjs related code. When I add the line (or the equivalent require)

import Spark from 'spark'

I get the following warning in my build log:

WARNING in ./~/spark/dist/spark.min.js
Critical dependencies:
1:113-120 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/spark/dist/spark.min.js 1:113-120

When I refresh the page I have an error:

Uncaught TypeError: Cannot read property 'call' of undefined
    __webpack_require__ @ app.js:510
    fn @ app.js:76
    (anonymous function) @ spark.min.js:7
    (anonymous function) @ spark.min.js:734
    ../lib/Promise @ spark.min.js:7
    s @ spark.min.js:1
    (anonymous function) @ spark.min.js:15
    ../device @ spark.min.js:1
    s @ spark.min.js:1
    (anonymous function) @ spark.min.js:14
    .../vendor/jquery.modal.min.js @ spark.min.js:1
    s @ spark.min.js:1
    e @ spark.min.js:1
    (anonymous function) @ spark.min.js:1
    (anonymous function) @ spark.min.js:9
    .... // so on

I’ve tried requiring the src files from the lib directory but they don’t build. Any hints?

Hey, @wilsk,

I’m not familiar with webpack or react, but I may imagine it has something to do with the difference in the way modules are required. The spark JS library uses CommonJS to export its functionality. Perhaps check to see if there is a CommonJS plugin for react? I haven’t had a chance to check out react yet, so apologies if this isn’t a relevant suggestion.

— nexxy

@nexxy thanks - I think you are right. I could’t get it to work, but I’ve switched to an electron build which seemed to make the problem go away :smile: