choojs / nanohtml

:dragon: HTML template strings for the Browser with support for Server Side Rendering in Node.
MIT License
686 stars 49 forks source link

babel + rollup import error #171

Closed bennlich closed 4 years ago

bennlich commented 4 years ago

In my main.js I have:

import html from 'nanohtml';

My .babelrc:

{
  "presets": [
    ["@babel/env", {"modules": false}]
  ],
  "plugins": [
    ["./node_modules/nanohtml/lib/babel.js", {
      "useImport": true
    }]
  ]
}

And when I try to rollup:

src/main.js: (1:7)
[!] Error: 'default' is not exported by node_modules/nanohtml/lib/append-child.js, imported by src/main.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
src/main.js (1:7)
1: import _appendChild from "nanohtml/lib/append-child";
          ^

:( Any ideas what's going on here? Seems like babel is not transforming the module.exports statement in nanohtml/lib/append-child?

Versions:

  "devDependencies": {
    "@babel/core": "^7.10.4",
    "@babel/preset-env": "^7.10.4",
    "@rollup/plugin-babel": "^5.0.4",
    "@rollup/plugin-node-resolve": "^8.1.0",
    "rollup": "^2.18.1",
    "sass": "^1.26.5"
  },
bennlich commented 4 years ago

I was able to import nanohtml with rollup using the @rollup/plugin-commonjs module.

In main.js:

import html from 'nanohtml/lib/browser';

And my .babelrc.json:

{
  "presets": [
    ["@babel/env", {"modules": false}]
  ]
}

Should I update the nanohtml readme with this method?

goto-bus-stop commented 4 years ago

@bennlich if you could add that to the readme that would be great!

bennlich commented 4 years ago

Kk! Have a look at: https://github.com/choojs/nanohtml/pull/172

goto-bus-stop commented 4 years ago

merged 💃