Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import RA default export doest not works #456

Closed
guillaumearm opened this issue Mar 17, 2018 · 16 comments
Closed

import RA default export doest not works #456

guillaumearm opened this issue Mar 17, 2018 · 16 comments

Comments

@guillaumearm
Copy link
Collaborator

default export seems to not works like ramda does.

import RA from 'ramda-adjunct' // RA is undefined
import R from 'ramda' // R is OK

import * as RA from 'ramda-adjunct' // RA is OK
import * as R from 'ramda' // R is OK

I don't understand why, maybe need to investigate https://github.com/ramda/ramda/blob/master/.babelrc

@guillaumearm
Copy link
Collaborator Author

guillaumearm commented Mar 17, 2018

I have made some investigations on ramda :

import R from 'ramda' // use "main" field (commonjs)
import * as R from 'ramda' // use "main" field (commonjs)

It seems like Ramda have a bug and never really expose es module.
In my case, "module" field is ignored, but "jsnext:main" works fine.

import RA from 'ramda-adjunct' // use "jsnext:main" field (es)
import * as RA from 'ramda-adjunct' // use "jsnext:main" field (es)

I can't find a case where "module" is used, I test this with babel 6 and this configuration :

{
  "presets": [
    ["es2015"],
    ["stage-0"]
  ]
}

Related to ramda/ramda#2355

@Andarist
Copy link
Contributor

Andarist commented Mar 18, 2018

How do u consume ramda-adjunct? node? webpack? rollup? other?

btw. I strongly believe this is expected behaviour. You are not supposed to be able to import default from RA, it's a namespace library and import * as RA is correct for this use case.

@guillaumearm
Copy link
Collaborator Author

In my case I've just node, so import are replaces by require, commonJs is used, everything seems normal.

You are not supposed to be able to import default from RA, it's a namespace library and import * as RA is correct for this use case.

You right, but I have to know why import R from 'ramda' is working while import RA from 'ramda-adjunct' doesn't

@Andarist
Copy link
Contributor

Might be because ramda uses custom transform from esm to cjs - https://github.com/ramda/ramda/blob/9e5107e6e021b35179401eb719283cd835687d51/scripts/transpile/esm-to-cjs.js . This is just a guess though - you should be able to debug this easily by inspecting transformed outputs of both.

@quangv
Copy link

quangv commented Apr 19, 2018

I'm having same issue:

export 'default' (imported as 'RA') was not found in 'ramda-adjunct

Perhaps we should change docs?

https://github.com/char0n/ramda-adjunct/blob/master/README.md#es6

ES6

import RA from 'ramda-adjunct'
RA.isArray([]);

@Andarist
Copy link
Contributor

Andarist commented Apr 20, 2018

@quangv You are not supposed to be able to import default from RA, it's a namespace library and import * as RA is correct for this use case.

And yeah - I guess @char0n would appreciate a PR with docs change 😉

@char0n
Copy link
Owner

char0n commented Apr 22, 2018

Yes the current behavior * as RA is due to the tree shaking. We can add additional mechanism that supports import RA from 'ramda-adjunct' but now we don't support. I'll fix the documentation to reflect that.

@guillaumearm
Copy link
Collaborator Author

Because we looking for consistance between RA and Ramda, I think we should export default too.

@Undistraction
Copy link
Collaborator

I agree, as long as it doesn't effect Treeshaking.

char0n added a commit that referenced this issue Apr 22, 2018
@Andarist
Copy link
Contributor

@guillaumearm ramda does not export default, so you are already consistent 😉

@guillaumearm
Copy link
Collaborator Author

@Andarist : I mean it's work when you import ramda as default.

@Andarist
Copy link
Contributor

It really shouldnt until ur setup is in some way not-standard.

@Undistraction
Copy link
Collaborator

Undistraction commented Apr 23, 2018

@Andarist The problem is that someone used to using Ramda like this:

import R from 'ramda'

R.length('abc') //=> 3

Will expect Ramda Adjunct to function in the same way. However using ES6 imports the following will not work (works fine with require()):

import RA from 'ramda-adjunct' 

RA.isBoolean('abc') // => RA is undefined

@Andarist
Copy link
Contributor

Since ramda@0.25 it's not possible to import ramda as default, see upgrade guide

@Undistraction
Copy link
Collaborator

@Andarist Thanks for the link. In that case, as long as we aren't doing it anywhere in the docs or examples, I think we can safely close this issue.

@guillaumearm
Copy link
Collaborator Author

Like @Andarist said :

You are not supposed to be able to import default from RA, it's a namespace library.

So now that consistency issues between ramda and ramda-adjunct are fixed, it's ok to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants