ef4 / ember-browserify

ember-cli addon for easily loading CommonJS packages from npm via browserify.
MIT License
172 stars 28 forks source link

Importing lib from npm gives an object instead of function #31

Closed michaelBenin closed 9 years ago

michaelBenin commented 9 years ago

Library we are importing:

https://github.com/defunctzombie/num/blob/master/num.js

Import code:

import num from 'npm:num'

Returns an object:

{ default: function }

Is there a way to import this where num is a function and not an object?

michaelBenin commented 9 years ago

Is it because the package.json main's property?

https://github.com/defunctzombie/num/blob/master/package.json#L17

ef4 commented 9 years ago

This is the expected behavior. It keeps you compatible with the ES6 import syntax used everywhere in ember-cli. You'll notice that every other dependency behaves the same way (try require('ember') in the console).

Instead of writing this:

var myThing = require('npm:my-thing');

write this:

import myThing from 'npm:my-thing';

And the ES6 transpiler will do the right thing for you.

michaelBenin commented 9 years ago

Ah ok, I was debugging with a debugger statement and using the imported library.

I see what you are saying now. Thank you.