I would like to do this
var debug = require('debug')('myapp');
... in ES6 without creating an extra variable. Can it be done?
import Debug from 'debug';
const debug = Debug('myapp');
(as lemieuxster said... addressing the fact that it is still listed under unanswered questions)
Note as mentioned in the comments, this will work for modules exported with the es6 syntax, that is whenever export default expression was used, which would give way to a require of the form var debug = require('./debug').default('myapp');. If the module you are importing used an export syntax of the type export const Debug = expression or export {Debug} or module.exports = {Debug : expression} then you will have to use import {Debug} from 'debug';
debug module doesn't have any default exports though so this wouldn't work. Although I guess this is only shows when using TypeScript. In that case you'd want to: import * Debug from 'debug' and then const debug = Debug('app')('scope');
as in there - import * as Debug from 'debug';, but then rollup won't like it (cannot call a namespace ('Debug')).
debugmodule was set up to support ES6 exports the answer is still essentially "No." There needs to be the import directive then you use the imported bit.import Debug from 'debug'; let debug = Debug('myapp');or similar. Possibly usingSystem.importwould remove the extra object, but it creates a nested function mess.