choojs / hyperx

🏷 - tagged template string virtual dom builder
BSD 2-Clause "Simplified" License
1.02k stars 48 forks source link

Rollup #54

Closed rbiggs closed 7 years ago

rbiggs commented 7 years ago

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?

yoshuawuyts commented 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 .

rbiggs commented 7 years ago

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 ☕️☕️

slaskis commented 7 years ago

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'
rbiggs commented 7 years ago

Yup. Tried that and got:

Error: 'default' is not exported by node_modules/hyperx/index.js
styfle commented 7 years ago

Did you try

import * as hyperx from 'hyperx';
rbiggs commented 7 years ago

With

import * as hyperx from 'hyperx'

I get:

Error: Cannot call a namespace ('hyperx')
rbiggs commented 7 years ago

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.