microenvi
microenvi copied to clipboard
Alias does not work for imported module.
Hi there! 👋
I'm running into an issue where importing a module, that then imports an aliased dependency, throws an error. I'm not sure if this is an issue with this project or the upstream Microbundle.
Logs
npm run dev
npm run dev
> [email protected] dev /Users/JHAMILTON/work/micro
> microenvi --alias react=preact-compat,react-dom=preact-compat
microenvi running on: 3000
node-resolve: setting options.module is deprecated, please override options.mainFields instead
node-resolve: setting options.jsnext is deprecated, please override options.mainFields instead
Watching source, compiling to public/scripts:
Error: Could not load preact-compat (imported by /Users/JHAMILTON/work/micro/node_modules/@material-ui/core/esm/styles/useTheme.js): ENOENT: no such file or directory, open 'preact-compat'
at /Users/JHAMILTON/work/micro/node_modules/rollup/dist/rollup.js:21723:19
at async Promise.all (index 1)
at async Promise.all (index 8)
at async Promise.all (index 0)
at async Promise.all (index 0)
Reproduction
- Install dependencies
npm init --yes
npm install --save-dev microbundle microenvi preact preact-compat @material-ui/core
- Update the
package.json
with a newmain
and a script to run microenvi.
{
"main": "public/scripts/bundle.mjs",
"scripts": {
"dev": "microenvi --alias react=preact-compat,react-dom=preact-compat"
}
}
- Create html file
public/index.html
.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Hello World</title>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>
</head>
<body>
<div id="root"></div>
</body>
</html>
- Create js entry file
src/index.js
.
import { createMuiTheme } from "@material-ui/core/styles";
const theme = createMuiTheme({});
- Run Microenvi.
npm run dev
Addendum, running npx microbundle build -i src/index.js --alias react=preact-compat,react-dom=preact-compat --no-compress --define process.env.NODE_ENV=production
doesn't seem to throw an error. It'd seem the problem lies somewhere on the Microenvi side.
Did a little more digging and it looks like this may be an issue with how dependencies are structured. After install, running rm -rf node_modules/microenvi/node_modules
makes the build work 🤔