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
Error when using file JS built by microbundle "Uncaught ReferenceError: require is not defined" #1078
Comments
Hey, thanks for popping over here, it's a bit easier to answer in full. As mentioned, CJS is not suitable for browser use. You want the UMD, ESM, or Modern bundles for this. It seems this is what you want to do anyhow, as you're adding Edit: Here's a demo: https://github.com/rschristian/demo__microbundle-preact-widget, certainly let me know if you have any questions on any part of it |
Thank you, maybe I have solved the above error, but there is another problem I have, I am using .env variables and the current browser cannot read it 'Uncaught ReferenceError: process is not defined' |
Indeed. // input
console.log(process.env.MY_VAR);
// output
console.log("hello world!"); |
Really, I think environment variables should be bind, and seems like my tailwindcss is not bundled |
I don't really have much of an opinion either way, but this is the way env vars work for now anyways. Did you follow the example I gave for importing CSS? I'll need more info to go on as, as my demo shows, it's working as intended. |
Are you importing your built Tailwind CSS like Additionally, Tailwind produces quite large outputs, keep in mind that this will bloat your bundles by a non-negligible amount. |
You need to provide a reproduction, "my tailwind classes don't work" isn't enough information for me to offer any real help unfortunately. Are you creating a |
It's hard for you if I keep asking around, this is my repo and everything I configure is here, you can see how I'm doing |
This won't work. You need to do it as I've done. |
That's just TypeScript, you can ignore it with a // @ts-ignore
import styles from './style.css'; or add an ambient declaration file like this: // src/global.d.ts
declare module '*.css' {
const css: string;
export default cssl;
} Totally unrelated to Microbundle.
|
Can you help me with this problem, if I have 2 env variables how can I define them with |
Use a comma to separate them, e.g.:
|
|
I can't reproduce, that works just fine for me. Here's a demo: https://github.com/rschristian/demo__microbundle-define |
Many thanks for helping me, I did it |
I'll close this out in that case, but feel free to reply here or open a new issue if you continue to have any problems. |
Hi, This is part of my package.json to use microbundle build 1 preact widget
As a result, I get an index.js file in the dist folder, I use it to embed my page with a script tag
<script type="module" id="embed-form" src="/dist/index.js"></script>
Browser console error '(Uncaught ReferenceError: require is not defined)'
Do you have a solution for that ?
The text was updated successfully, but these errors were encountered: