Skip to content

Alias does not work for imported module. #4

@jakehamilton

Description

@jakehamilton

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     

> micro@1.0.0 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

  1. Install dependencies
npm init --yes

npm install --save-dev microbundle microenvi preact preact-compat @material-ui/core
  1. Update the package.json with a new main and a script to run microenvi.
{
  "main": "public/scripts/bundle.mjs",
  "scripts": {
    "dev": "microenvi --alias react=preact-compat,react-dom=preact-compat"
  }
}
  1. 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>
  1. Create js entry file src/index.js.
import { createMuiTheme } from "@material-ui/core/styles";

const theme = createMuiTheme({});
  1. Run Microenvi.
npm run dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions