Passing arguments to class constructors
<p>I've written the below module, but importing it doesn't work as expected. Files (abbreviated for simplicity):</p>

<p><code>templates.js</code></p>

<pre><code>'use strict';

export default class Templates {
    constructor (args) {
        this.files = [{
            name: `${args.name}.js`,
            path: 'src/',
            content: ''
        }];
        /* code omitted */
    }
};
</code></pre>

<p>I'm trying to use it like so:</p>

<p><code>index.js</code></p>

<pre><code>import Templates from './templates'

const opts = {name: 'app'};
/* code ommited */
console.log('Templates &gt;&gt;', typeof Templates);
console.log('Templates &gt;&gt;', new Templates());

let tmpls = new Templates(opts);
console.log(tmpls.files[0].name);
</code></pre>

<p>But I get the following error trace in console.</p>

<pre><code>npm ERR! Linux 3.16.0-38-generic
npm ERR! argv "/home/wesleycoder/.nvm/versions/node/v5.1.0/bin/node" "/home/wesleycoder/.nvm/versions/node/v5.1.0/bin/npm" "init"
npm ERR! node v5.1.0
npm ERR! npm  v3.3.12

npm ERR! Cannot read property 'name' of undefined
</code></pre>

<p>And yes this is a <code>~/.npm-init</code> script for who may ask.</p>

<p><strong>Edit:</strong>
Thanks to @low_ghost for the useful response.</p>

<p>I've figured out that my problem wasn't about exporting and importing classes.
It was actually about passing arguments to this class but not about not passing the argument. So I've changed the title for concision.</p>

<p>The <code>console.log(new Templates())</code> without any argument was intentional in my code.
The error that I was trying to solve was about instantiating the object and getting the files array, but I was passing the arguments directly from the <a href="https://github.com/tj/commander.js" rel="nofollow noreferrer"><code>commander.js</code></a> library and the arguments passed were "overkill" to this task, so I simplified the arguments by taking the input from <code>commander.js</code> and assigning each one in a property in an empty object then passing this object along the constructor, this allowed me to take <code>readline-sync</code> and read input from options not passed and make the script more awesome, after this all worked fine.</p>

<p>Would be fine if <code>commander.js</code> had any option to give the options passed without the extra weight of the library properties.</p>

<p><strong>Edit2:</strong>
After all <code>commander.js</code> was not useful because I couldn't pass the arguments along <code>npm init</code> command to the script it self.</p>