Getting error when building project for production
When we are trying to build our project with
npm run build
command, we are getting the following error
Error occurred prerendering page "/_not-found"
and ReferenceError: self is not defined
3 Replies
Hi @Rohit. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It seems like you're encountering an error during the production build of your project. Based on the knowledge sources provided, there are a few potential issues and solutions that might help you resolve this problem.
1. CommonJS and ESModules Issue with Vite:
If you are using Vite with Refine and Ant Design, there might be issues related to CommonJS and ESModules. This was noted in GitHub Issue #3187 (https://github.com/refinedev/refine/issues/3187). The solution involved patching the
node_modules/@pankod/refine-antd/dist/esm/index.js
to replace picker imports from lib
to es
.
2. Build Command:
Ensure you are using the correct build command. In some cases, using npm run refine build
instead of npm run build
has resolved issues, as mentioned by a community member in the Discord support thread (https://discord.com/channels/837692625737613362/1208733702008602655).
3. Next.js Specific Issues:
If you are using Next.js, make sure you are following the correct build steps. As noted in GitHub Issue #5648 (https://github.com/refinedev/refine/issues/5648), you need to build your project before starting it in production:
4. Module Export Issues:
If you encounter issues with module exports, such as missing exports from @refinedev/antd
, ensure that you have the correct versions of your dependencies and that they are properly installed. This was highlighted in GitHub Issue #5926 (https://github.com/refinedev/refine/issues/5926).
Given the specific error messages you mentioned (Error occurred prerendering page "/_not-found"
and ReferenceError: self is not defined
), it might be related to the environment or specific code in your project. Here are some general steps you can take:
- Check for Environment-Specific Code:
Ensure that any code that relies on browser-specific globals (like self
, window
, etc.) is not executed during the server-side rendering (SSR) phase. You can use conditional checks to ensure such code only runs in the browser.
- Update Dependencies:
Make sure all your dependencies are up to date. Sometimes, issues are resolved in newer versions of the libraries.
If these steps do not resolve your issue, you might need to provide more specific details or logs to get further assistance. For more detailed guidance, you can refer to the Refine documentation (https://refine.dev/docs).
If you need further assistance, please provide more details about your setup and the exact steps you have taken so far.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@634801931000217610> kapa.ai is still learning and improving, please let us know how it did by reacting below
continuing-cyan•2mo ago