react-hot-toast cannot be built by Vite - reactjs

I have used the React-Hot-Toast in my React application bootstrapped by Vite.
The website is running smoothly in the developing mode.
However, I encounter an error when I am building the site by npm run build.
[vite]: Rollup failed to resolve import "react-hot-toast" from "src/App.jsx".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
I followed its suggestion to put the rollupOptions in the vite.config.js.
Though it was successfully built, the website in the preview mode crashed immediately.
And I have received the following error in the browser's console.
Uncaught TypeError: Failed to resolve module specifier "react-hot-toast". Relative references must start with either "/", "./", or "../".
I have no idea what I should be done or if I had made something wrong.
Since the website is widely applying react-hot-toast, I would love to see if the problem can be fixed without replacing the library.
Thanks in advance.

Related

Error: Too many re-renders issue error, on deployed server env but works fine in local env

In my react js project once I build npm run build and deploy it on the server let's say dev environment using Webpack. The rest of the project works fine but when I click one specific button in my UI in the dev environment. I get the following error -
Error: Minified React error #301; visit https://reactjs.org/docs/error-decoder.html?invariant=301 for the full message or use the non-minified dev environment for full errors
Too many re-renders. React limits the number of renders to prevent an infinite loop.
But when I try to replicate the issue in my local environment it works completely fine, without any issues. I am not able to find the root cause of this issue.
Please help

Uncaught Error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code

I don't know what's going on I am making a frontend using vite + react for my mern project and suddenly starts encountering this error.
Error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code.
git repo link : https://github.com/Gaurav200247/E-Book-Store-Mern-Project
Had the same issue, the "events" module was in sub-dependencies, I added it manually by "npm install events", then the issue disappeared.
Make sure that:
You are importing the correct library in your code.
The library you are attempting to use is directly installed in your project, libraries available as sub-dependencies will not work.

Suprising Babel error after upgrading a Node.js module (monaco-editor)

I'm working on an React-based web application (created using CRA), so it uses Babel to transpile and pack our code and Node.js modules. Creating the production build worked fine until I upgraded the monaco-editor Node.js module from 0.20.0 to 0.21.2. After that an error started showing up, which is totally unexpected and probably caused by (valid) code changes in monaco-editor:
Creating an optimized production build...
Failed to compile.
./node_modules/monaco-editor/esm/vs/editor/contrib/suggest/wordDistance.js
Error: <path>/node_modules/monaco-editor/esm/vs/editor/contrib/suggest/wordDistance.js: unknown Expression of type "ClassExpression"
at Array.forEach (<anonymous>)
I'm pretty sure this is not a failure in the monaco-editor Node.js module and my web search brought me to some code that made me think this is an error printed by Babel. Beside others, I found this pull request for Babel which fixes a very similar error message.
There's no other information in the error message, so I cannot be 100% sure, and therefore I would also very much welcome anything I could use to get more context for this error message.
I created a minimal example which produces this behavior and allows to prove that the monaco-editor upgrade is the culprit: https://github.com/mike-lischke/babel-test.
But since this is valid JavaScript code, I supposed the real culprit is Babel, not being able to deal with the used syntax (or maybe I need a newer version, but since this is all integrated in CRA it's tricky to use newer versions of automatically installed components).
At the time being there's no other way than to return to the previous version of Monaco editor.

React app deployed to GitHub giving me a minified error #152

I am having a problem with my React application. I am trying to deploy the website to GitHub pages but I am getting this error:
Error: "Minified React error #152; visit https://reactjs.org/docs/error-decoder.html?invariant=152&args[]=u for the full message or use the non-minified dev environment for full errors and additional helpful warnings."
The error is telling me to use the non-minified development environment, but I cannot figure out how to do this.
Here is a link to my GitHub repository if you would like to check!
GitHub repository
I am not sure how to solve this since this is the first time I try to deploy a website. I tried installing some dependencies like Webpack, Babel, and Parcel to bundle my files into a readable JavaScript file, but my guess is that something is not being translated properly, meaning that there might be a syntax error somewhere in my code.
When running the Webpack dependency I did get a series of errors, that is why I installed some other libraries and loaders:
Error on Terminal
I ran into the same issue. The issue occurred wherever I deployed a production build to - locally or Firebase. I found that I had some comments in my render/return code and removing them solved this for me, as discussed at https://github.com/facebook/create-react-app/issues/8687.
I removed the comments as suggested, but ended up using gh-pages instead of deploying via a docs directory on github, so it worked in the end. I have deployed other apps after that with comments and they work just fine.
So if you ever run into this, try gh-pages instead

I get internal server error while running next js app with styled component

I'm using Next.js with styledcomponent, It gets no error in Dev mode. but while running in Build production mode. I get an error. without line number or file name.
I have also opened an issue Github
https://github.com/zeit/next.js/issues/5932
ERROR
NODE_ENV=production node server.js
Ready on http://localhost:3000
Error: An error occurred. See https://github.com/styled-components/styled-components/blob/master/src/utils/errors.md#1 for more information. Additional arguments: undefined
at new StyledComponentsError (/Users/rahulkishan/Documents/React_Mobile_and_web/ReactWebV1/purchaseweb/node_modules/styled-components/dist/styled-components.cjs.js:161:58)
at constructWithOptions (/Users/rahulkishan/Documents/React_Mobile_and_web/ReactWebV1/purchaseweb/node_modules/styled-components/dist/styled-components.cjs.js:2182:13)
at styled (/Users/rahulkishan/Documents/React_Mobile_and_web/ReactWebV1/purchaseweb/node_modules/styled-components/dist/styled-components.cjs.js:2126:12)
at Object. (/Users/rahulkishan/Documents/React_Mobile_and_web/ReactWebV1/purchaseweb/.next/server/static/i2aIDkRZkhvVhtPxvk4BE/pages/index.js:4504:77)
Why it shows this error in Build mode only. Not in dev mode.
We have built a large app.
It is really difficult to find the problem.
Error has its path
static/../pages/index.js
And line number as well
After giving npm run build
Nexts js creates a build folder as
/.next/server/static
Inside that folder you will be able to see the complete production code.

Resources