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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing exports within build #8800

Closed
7 tasks done
Kyzegs opened this issue Jun 26, 2022 · 4 comments
Closed
7 tasks done

Missing exports within build #8800

Kyzegs opened this issue Jun 26, 2022 · 4 comments

Comments

@Kyzegs
Copy link

Kyzegs commented Jun 26, 2022

Describe the bug

I'm running into an odd issue with a dependency when building with Vite.

Here's a simple component using react-responsive:

import React from 'react';
import { useMediaQuery } from 'react-responsive';

const Component = () => {
  const isMobile = useMediaQuery({ query: '(max-width: 991px)' });

  if (isMobile) {
    return <span>Mobile view</span>;
  }

  return <span>PC View</span>;
};

export default Component;

After building with Vite (vite build) and visiting my website, it'll return me an error:

TypeError: reactResponsive.exports.useMediaQuery is not a function

I've tried numerous things to fix this issue. One odd fix is by simply logging the imported function.

import React from 'react';
import { useMediaQuery } from 'react-responsive';

+ console.log(useMediaQuery);

const Component = () => {
  const isMobile = useMediaQuery({ query: '(max-width: 991px)' });

  if (isMobile) {
    return <span>Mobile view</span>;
  }

  return <span>PC View</span>;
};

export default Component;

I've also run Vite in development mode (vite), and this issue did not arise within that environment.

Reproduction

SOON

System Info

System:
  OS: Windows 10 10.0.19044
  CPU: (24) x64 AMD Ryzen 9 3900XT 12-Core Processor
  Memory: 12.90 GB / 31.95 GB
Binaries:
  Node: 16.15.0 - D:\Program Files\nodejs\node.EXE
  Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
  npm: 8.5.5 - D:\Program Files\nodejs\npm.CMD
Browsers:
  Edge: Spartan (44.19041.1266.0)
  Internet Explorer: 11.0.19041.1566
npmPackages:
  @vitejs/plugin-react: ^1.3.2 => 1.3.2
  vite: ^2.9.12 => 2.9.12

Used Package Manager

npm

Logs

No response

Validations

@lmiller1990
Copy link

I am seeing something similar too - exports is not defined. Same code base builds fine on mac/linux.

@github-actions
Copy link

Hello @Kyzegs. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@sapphi-red
Copy link
Member

It seems you are using 2.9.12. Please try 3.0.0-beta.3 too. It includes many fixes around CJS.

@Kyzegs
Copy link
Author

Kyzegs commented Jun 27, 2022

Using Vite 3.0.0-beta.4 solved the issue for me.

@Kyzegs Kyzegs closed this as completed Jun 27, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants