preactjs / wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
https://wmr.dev/
MIT License
4.92k stars 109 forks source link

Build fails when changing the `root` config option in `wmr.config.js` #931

Closed smithbm2316 closed 2 years ago

smithbm2316 commented 2 years ago

Describe the bug Setting the root option in the wmr.config.js file breaks wmr build --prerender.

Error message from console: ```sh (!) Could not find generated URL for src/index.js (!) Could not find generated URL for src/index.js Wrote 23Kb to disk: dist/index.html 448b dist/index.984d9db8.js 17Kb dist/assets/style.e6ee4bcf.css 423b dist/assets/style.module.757ddc6c.css 77b dist/chunks/prerender.2f374aaf.js 5.0Kb dist/chunks/index.9cc1b67c.js 249b The following error was thrown during prerendering: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/smithbm/code/notes-ui/preact-wmr/dist/__ENTRY__/0' imported from /Users/smithbm/code/notes-ui/preact-wmr/[worker eval] at new NodeError (internal/errors.js:322:7) at finalizeResolution (internal/modules/esm/resolve.js:318:11) at moduleResolve (internal/modules/esm/resolve.js:776:10) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11) at Loader.resolve (internal/modules/esm/loader.js:89:40) at Loader.getModuleJob (internal/modules/esm/loader.js:242:28) at Loader.import (internal/modules/esm/loader.js:177:28) at importModuleDynamically (internal/process/execution.js:87:29) at async importModuleDynamicallyWrapper (internal/vm/module.js:451:15) error Command failed with exit code 1. ```

To Reproduce Steps to reproduce the behavior:

  1. Use the following config for wmr.config.js after starting with a fresh output from the create-wmr package:
    
    import { defineConfig } from 'wmr';

export default defineConfig({ alias: { react: 'preact/compat', 'react-dom': 'preact/compat', }, root: 'src', });


2. Rename the `public` directory to `src` (`mv public src`)
3. Run `wmr build --prerender`

**Expected behavior**
The build should complete properly. 

**Bug occurs with:**

- [x] `wmr build` (production)

**Desktop (please complete the following information):**

- OS: MacOS 11.6.5
- Node Version: 14.19.0
- WMR Version: 3.7.2

**Additional context**
I have solved the issue by updating the documentation to display the proper config option of `public` instead of `root`, which is where my confusion stemmed from. I also added some extra documentation of the other `wmr build` CLI options that weren't in the markdown documentation yet.