question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rollup Error: Could not resolve '../dom' from src/preact/src/vdom/diff.js

See original GitHub issue

I’m trying to use preact with rollup, but no babel. I hit a small snag that should be easy to fix.

I have this repo as a submodule directly in my src folder and am trying to use it like this:

/* eslint-env browser */
import { Component, h, render } from './preact/src/preact.js'

/** Example classful component */
class App extends Component {
  componentDidMount () {
    this.setState({ message: 'Hello!' })
  }
  render (props, state) {
    return (
      h('div', {id: 'app'},
        h(Header, { message: state.message }),
        h(Main)
      )
    )
  }
}

/** Components can just be pure functions */
const Header = (props) => {
  return h('header', null,
    h('h1', null, 'App'),
    props.message && h('h2', null, props.message)
  )
}

/** Instead of JSX, use: h(type, props, ...children) */
class Main extends Component {
  render () {
    const items = [1, 2, 3, 4, 5].map((item) => (
      h('li', {id: item}, 'Item ' + item)
    ))
    return (
      h('main', null,
        h('ul', null, items)
      )
    )
  }
}

render(h(App), document.body)

The problem is src/vdom/component.js and src/vdom/diff.js both import dom as simply ../dom, but they need to be ../dom/index because rollup’s default search path doesn’t support auto index on folders.

Once I tweak those two files, it seems to bundle just fine.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
creationixcommented, Aug 7, 2017

Well, I checked and the plugin is much lighter-weight than I expected (npm dependencies tend to be giant).

$ npm install --save-dev rollup-plugin-node-resolve
$ du -sh node_modules/
668K	node_modules/
$ tree node_modules/
...
103 directories, 162 files

My project doesn’t have a node_modules yet. Yes I personally have an aversion to including hundreds of files and over half a megabyte of code, having to manage node_modules in my .gitignore as well as track package.json and package-lock.json, and adding a build dependency to npm in my flow just to avoid adding 14 bytes to upstream preact.

I understand I’m fairly unique and most JS developers already use npm and much larger node_modules trees already and barely notice the cost of adding this plugin.

You also bring up a very good point about third-party components that depend on the node resolution strategy. Again I’m a unique case and am not consuming any existing components and so am not affected by this. Even the 14 bytes added to preact won’t affect me because I’m using rollup and it erases all the import and exports statements by just inlining everything together.

The choice is yours, I respect your preferences as the maintainer. Just a humble request to help simplify for my fairly odd workflow.

0reactions
developitcommented, Aug 20, 2017

I’m happy to make the change - one of the index files is due for renaming anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Could not resolve entry module React + Rollup
After spending some while digging for the solution, I finally got to solve this problem. My Configuration looks exactly the same except the...
Read more >
Handling 3rd-party JavaScript with Rollup - Mixmax
Rollup is lighter, faster, and less complicated. Learn how to handle 3rd-party JavaScript with Rollup and how to use Rollup with external ...
Read more >
An Introduction to the Rollup.js JavaScript Bundler - SitePoint
Rollup.js is a next-generation JavaScript module bundler from Rich Harris, the author of Svelte. It compiles multiple source files into a ...
Read more >
Bundling with Rollup - Vue.js 3 Course
Running this again gives us: [!] Error: Could not resolve './mount' from src/index.ts. That's because rollup does not understand TS.
Read more >
Trying Rollup for React Applications | by Nathan Sebhastian
Rollup is a module bundler for JavaScript that works similarly to Webpack, but is ... "test": "echo \"Error: no test specified\" && exit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found