Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias does not work for imported module. #4

Open
jakehamilton opened this issue Oct 3, 2020 · 2 comments
Open

Alias does not work for imported module. #4

jakehamilton opened this issue Oct 3, 2020 · 2 comments

Comments

@jakehamilton
Copy link

jakehamilton commented Oct 3, 2020

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

  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
@jakehamilton
Copy link
Author

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.

@jakehamilton
Copy link
Author

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 馃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant