Closed aberba closed 1 year ago
Could you please provide reproduction instructions and a full demo for this?
Its a product app and what was causing the problem was a recursive import of modules in an api route. Had to play puzzle game before it figured out. Will be helpful to have nextjs detected when two modules import each others exported functions or import each other. Recursive import problem.
Please provide a complete reproduction so that we can have a look (as asked for before)
I can't provide a reproduction code from a proprietary codebase.
And it's not even about the code, it a Recursive import problem
which means two files import each other. You may try it with any code based. When that happens, next API routes breaks without any clear error what happened. Create React App has this thing checked.
You may try it with any code based
So you can provide a minimal reproduction that we can look into then? 🤔
File one
import {writeName} from "./file2.js"
writeName();
export function writeEmail(){}
File two
import {writeEmail} from "./file1.js"
writeName();
export function writeName(){}
Both are importing code from each other. It sometimes happen when using a large codebase will lots of reusable code.
Having a very similar problem, but unfortunately do not have a repro step yet because it is very hard to track down. The evil of my issue is that it happens from time to time and not on each build time. And issue relates to pages, but not api routes for me although I have three of those.
Here is the cutted version of the output:
$ next build
info - Loaded env from /Users/furthur/Projects/temy/react-marketplace/.env.production
info - Loaded env from /Users/furthur/Projects/temy/react-marketplace/.env
info - Using external babel configuration from /Users/furthur/Projects/temy/react-marketplace/babel.config.js
Creating an optimized production build
Compiled successfully.
Automatically optimizing pages .
Error occurred prerendering page "/members/details/[memberID]". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /members/details/[memberID]
at pageNotFoundError (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:1:336)
at getPagePath (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/export/worker.js:13:188)
Error occurred prerendering page "/members/update/[memberID]". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /members/update/[memberID]
at pageNotFoundError (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:1:336)
at getPagePath (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/export/worker.js:13:188)
Error occurred prerendering page "/members/users/[memberID]". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /members/users/[memberID]
at pageNotFoundError (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:1:336)
at getPagePath (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/export/worker.js:13:188)
Error occurred prerendering page "/members/users/create". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /members/users/create
at pageNotFoundError (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:1:336)
at getPagePath (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/export/worker.js:13:188)
Automatically optimizing pages ..
Error occurred prerendering page "/members/users/create/[memberID]". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /members/users/create/[memberID]
at pageNotFoundError (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:1:336)
at getPagePath (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/export/worker.js:13:188)
----- MORE ERRO MESSAGES LIKE THAT FOR EACH PAGE -----
> Build error occurred
Error: Export encountered errors on following paths:
/
/404
/dashboard
/deals/buy
/deals/buy/[dealID]
/deals/create
/deals/find
/deals/sell
/deals/sell/[dealID]
/login
/members/create
/members/create/[firmRegulatoryID]
/members/details/[memberID]
/members/lookup
/members/update/[memberID]
/members/users/[memberID]
/members/users/create
/members/users/create/[memberID]
/members/users/details/[userID]
/members/users/update/[userID]
/policies
/policies/create
/policies/details/[policyID]
/policies/update/[policyID]
/preferences
/preferences/[preferenceID]
/preferences/create
/profile
/reporting
/requests
/reset-password
/roles
/roles/create
/roles/details/[roleID]
/roles/update/[roleID]
at exportApp (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/export/index.js:24:1103)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async build (/Users/furthur/Projects/temy/react-marketplace/node_modules/next/dist/build/index.js:37:218)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Its a hard to track error. Happens quite often with api routes in my case. Hard to track especially when you have lots of code. I suspect its a recursive import issue.
@dvakatsiienko Check this are you using require() and import mixed up?
@aberba
I have four required in a project:
redux-logger
in dev modeHere is code snippet for require
ing a redux-logger
:
/* Core */
import { getDefaultMiddleware } from '@reduxjs/toolkit';
/* Instruments */
import { ReduxState } from './types';
const middleware = [ ...getDefaultMiddleware<ReduxState>() ];
if (__DEV__) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createLogger } = require('redux-logger');
const logger = createLogger({
duration: true,
timestamp: false,
collapsed: true,
colors: {
title: () => '#139BFE',
prevState: () => '#1C5FAF',
action: () => '#149945',
nextState: () => '#A47104',
error: () => '#ff0005',
},
predicate: () => process.browser,
});
middleware.push(logger);
}
export { middleware };
Do you think one require could mess up entire import system in a project? 🤔 That is very interesting, definitely will look for it today. Thanks for an idea.
Made a test — importing createLogger
function using regular import increases a bundle size by 4kb
but does not removes an issue.
The reason I asked about it was because I also did some random changes in my code including removing all require()
. Not sure which fixed the code.
If you're importing a file which also imports another file...which also imports the first file, then It'll result in some kind of loop (recursive import). And Next.js doesn't seem to show where the issue is and it can be hard to debug in a large code base.
Please verify that your issue can be recreated with next@canary
.
please verify canary
label?We noticed the provided reproduction was using an older version of Next.js, instead of canary
.
The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. You can think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running npm install next@canary
and test it in your project, using your reproduction steps.
If the issue does not reproduce with the canary
version, then it has already been fixed and this issue can be closed.
canary
?The safest way is to install next@canary
in your project and test it, but you can also search through closed Next.js issues for duplicates or check the Next.js releases.
canary
now?Next.js does not backport bug fixes to older versions of Next.js. Instead, we are trying to introduce only a minimal amount of breaking changes between major releases.
An issue with the please verify canary
that receives no meaningful activity (e.g. new comments that acknowledge verification against canary
) will be automatically closed and locked after 30 days.
If your issue has not been resolved in that time and it has been closed/locked, please open a new issue, with the required reproduction, using next@canary
.
Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the :+1: reaction on the topmost comment (please do not comment "I have the same issue" without repro steps). Then, we can sort issues by votes to prioritize.
We look into every Next.js issue and constantly monitor open issues for new comments.
However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.
Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.
This issue has been automatically closed because it wasn't verified against next@canary. If you think it was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Feature request
Is your feature request related to a problem? Please describe.
When you miss an import directly or through a sub-modules in a next api route, ti does not report actual error.
In my case i get
I have not idea where the issue is. Notice ive used
...
to anonymise the pathDescribe the solution you'd like
Error message should include path of module file I tried to import