snabbdom: Rollup can't import Snabbdom

I’ve been trying to use this with Rollup. I installed it in a project with npm. I’m using syntax like this:

import {snabbdom} from 'snabbdom'

But Snabbdom never gets included in the final bundle. I also tried the following, to no avail:

import {init, h} from 'snabbdom'

I notice all the examples are using CommonJS require. Is it possible to load this as ES6 modules? If so, are there some working examples somewhere?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

@caridy, great thanks for your workaround, that helps me alot. I must notice that there is a little vacuum here for people who using ES6 modules, but not using TS. You can’t use origin .ts files, since you’re not in TS world, but processed files are already transpiled and may be ambiguous for Rollup. I believe, good solution would be to create additional es6 target (ts → es6), which would rid of all the typedefs but still be in ES6 modules syntax.

Anyway, workaround is just working, and I’m OK until it is so. Have nothing against TS, just not using it in every project.

This is a common problem with rollup when the compiled bundle is ambiguous. We have been battling the same thing, and we have tried to fix it via https://github.com/snabbdom/snabbdom/pull/247, but we have no traction on that PR at the moment. Basically, Rollup will check if the CJS has a default export or not to try to understand the shape of the package. In the case of snabbdom, the exports object is ambiguous due to the double exports everywhere.