Search code examples
aureliajspmes6-module-loader

Importing an ES6 module using jspm & using in Aurelia


I'm trying to use the querystring package in an Aurelia application but getting Cannot read property 'stringify' of undefined error in the browser console.

These are the steps I took:

  • Install using jspm install querystring
  • Add import {querystring} from 'querystring' into the Aurelia model
  • Use in my model like so:

    import {querystring} from 'querystring';
    
    export class App {
    
    criteria_words;
    criteria_location;
    
    constructor() {
    }
    
    submit() {
        console.log(querystring.stringify(this));
    }
    }
    

What step am I missing?


Solution

  • First, jspm install querystring will not install the library that you have mentioned. The command that you should run is this:

    jspm install npm:qs
    

    Then, you can import and use it like this:

    import querystring from 'qs';
    // call querystring.stringify(someObject);
    

    Or

    import {stringify} from 'qs';
    // call stringify(someObject);