Closed rbiggs closed 7 years ago
Hmm, I haven't used Rollup with Choo, but given that we only ever expose commonJS modules, perhaps https://github.com/rollup/rollup-plugin-commonjs would be the right solution?
On Thu, Sep 14, 2017 at 6:24 AM Robert Biggs notifications@github.com wrote:
I use Rollup to bundle my code. I use it so I can organize a project's code as ES6 modules. I can't seem to find a way to import Hyperx with Rollup. I've successfully used other NPM modules with Rollup, so I'm assuming its something about how hyperx is getting exported. I'd like to be able to do the following:
import {hyperx} from 'hyperx'const html = hyperx(h)// etc
But I'm not having any luck. I am using rollup-plugin-commonjs with rollup, so that's not the issue:
commonjs({ include: 'node_modules/**' })
But when I build, I get this error in the console:
Error: 'hyperx' is not exported by node_modules/hyperx/index.js
Any idea how to be able to use hyperx with Rollup like a normal ES6 module?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/choojs/hyperx/issues/54, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWles1Mw0iPJwH_P8ilrfo9FnY66zl9ks5siKptgaJpZM4PXCDk .
Actually, I am using rollup-plugin-commonjs
and usually it just works for commonjs modules. I'll take another look at my setup after a couple of ☕️☕️
Have you tried using the default export? It looks to me like hyperx is using module.export
and not exports.hyperx
.
import hyperx from 'hyperx'
Yup. Tried that and got:
Error: 'default' is not exported by node_modules/hyperx/index.js
Did you try
import * as hyperx from 'hyperx';
With
import * as hyperx from 'hyperx'
I get:
Error: Cannot call a namespace ('hyperx')
Finally found the solution, thanks to a thread by Rich Harris on Gitlab. For Rollup to be able to import and bundle hyperx with other ES6 module imports you need to have the rollup-plugin-commonjs
configured like this. Notice the ignoreGlobal: true
part.
commonjs({
include: 'node_modules/**',
ignoreGlobal: true
})
Maybe you guys should put something in your docs about using Hyperx with Rollup for other people using it with ES6 imports so they don't go through what I just did.
I use Rollup to bundle my code. I use it so I can organize a project's code as ES6 modules. I can't seem to find a way to import Hyperx with Rollup. I've successfully used other NPM modules with Rollup, so I'm assuming its something about how hyperx is getting exported. I'd like to be able to do the following:
But I'm not having any luck. I am using rollup-plugin-commonjs with rollup, so that's not the issue:
But when I build, I get this error in the console:
Any idea how to be able to use hyperx with Rollup like a normal ES6 module?