Rollup Error: Could not resolve '../dom' from src/preact/src/vdom/diff.js
See original GitHub issueI’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:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, I checked and the plugin is much lighter-weight than I expected (npm dependencies tend to be giant).
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 managenode_modules
in my.gitignore
as well as trackpackage.json
andpackage-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.
I’m happy to make the change - one of the index files is due for renaming anyway.