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

Uncaught ReferenceError: require is not defined #5054

Closed
l1x opened this issue Dec 1, 2021 · 6 comments
Closed

Uncaught ReferenceError: require is not defined #5054

l1x opened this issue Dec 1, 2021 · 6 comments

Comments

@l1x
Copy link

l1x commented Dec 1, 2021

Environment

  • Package version(s):
    "@blueprintjs/core": "4.0.0-beta.10",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"

  • Operating System: MacOS

  • Browser name and version: Chrome

Code Sandbox

Link to a minimal repro: https://github.com/DataDeft/web-debug

Steps to reproduce

Clone repo, yarn install, yarn build, yarn serve, open the link and watch the blank page.

Actual behavior

It seems when using Vite as opposed to Webpack this problem surfaces. I do not know enough of frontend development to be able to investigate myself.

Uncaught ReferenceError: require is not defined
at vendor.75daa434.js:64

Expected behavior

Run without error.

Possible solution

Not sure.

@adidahiya
Copy link
Contributor

That's surprising; we ship esm modules (see the /lib/esm/ folder in the built NPM package) and Vite should support those. It looks like similar issues / questions have been raised with Vite, like vitejs/vite#3409. You can probably work around this issue using vite-plugin-commonjs.

@adidahiya
Copy link
Contributor

Looking a bit more closely, though, it seems like these lines may be causing the problem:

export const IconSvgPaths16 = require("./generated/16px/paths") as Record<PascalCase<IconName>, string[]>;
export const IconSvgPaths20 = require("./generated/20px/paths") as Record<PascalCase<IconName>, string[]>;

Those are the only places we ship code referencing require(). I should be able to swap those back to use import statements instead...

@l1x
Copy link
Author

l1x commented Dec 1, 2021

Thanks @adidahiya! I am trying exactly that right now. :)

@adidahiya adidahiya self-assigned this Dec 1, 2021
@l1x
Copy link
Author

l1x commented Dec 1, 2021

Confirmed. Your change (that you linked above) is causing this. When I move back to version 3.51.3 it works because it uses still the old import ( as opposed to require).

@adidahiya
Copy link
Contributor

fixed in v4 by #5108

@l1x
Copy link
Author

l1x commented Feb 11, 2022

Thanks a lot @adidahiya !

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

No branches or pull requests

2 participants