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

Updating from 12.1.4 to 12.1.5: Error: Cannot find module 'next/dist/shared/lib/router/utils/routing-items.js' #36234

Closed
1 task done
davidye opened this issue Apr 17, 2022 · 24 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@davidye
Copy link

davidye commented Apr 17, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
Binaries:
  Node: 16.14.0
  npm: 8.3.1
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.1.6-canary.3
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

After updating from 12.1.4 => 12.1.5 (and 12.1.6-canary.3) I get this build error. Downgrading back to 12.1.4 resolves the issue.

next -p 8080

node:internal/modules/cjs/loader:933
const err = new Error(message);
^

Error: Cannot find module 'next/dist/shared/lib/router/utils/routing-items.js'
Require stack:

  • /Users/me/hello/client/.next/server/pages/_app.js
  • /Users/me/hello/client/node_modules/next/dist/server/require.js
  • /Users/me/hello/client/node_modules/next/dist/server/load-components.js
  • /Users/me/hello/client/node_modules/next/dist/build/utils.js
  • /Users/me/hello/client/node_modules/next/dist/build/output/store.js
  • /Users/me/hello/client/node_modules/next/dist/build/output/index.js
  • /Users/me/hello/client/node_modules/next/dist/cli/next-dev.js
  • /Users/me/hello/client/node_modules/next/dist/bin/next
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.mod._resolveFilename (/Users/me/hello/client/node_modules/next/dist/build/webpack/require-hook.js:183:28)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object../utils/routing-items (/Users/me/hello/client/.next/server/pages/_app.js:1229:18)
    at webpack_require (/Users/me/hello/client/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///./node_modules/next/dist/shared/lib/router/router.js:45:21)
    at Object../node_modules/next/dist/shared/lib/router/router.js (/Users/me/hello/client/.next/server/pages/_app.js:99:1)
    at webpack_require (/Users/me/hello/client/.next/server/webpack-runtime.js:33:42) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/Users/me/hello/client/.next/server/pages/_app.js',
    '/Users/me/hello/client/node_modules/next/dist/server/require.js',
    '/Users/me/hello/client/node_modules/next/dist/server/load-components.js',
    '/Users/me/hello/client/node_modules/next/dist/build/utils.js',
    '/Users/me/hello/client/node_modules/next/dist/build/output/store.js',
    '/Users/me/hello/client/node_modules/next/dist/build/output/index.js',
    '/Users/me/hello/client/node_modules/next/dist/cli/next-dev.js',
    '/Users/me/hello/client/node_modules/next/dist/bin/next'
    ]
    }

Expected Behavior

Build correctly

To Reproduce

See stack trace, 'next/dist/shared/lib/router/utils/routing-items.js' is missing from node_modules.

@davidye davidye added the bug Issue was opened via the bug report template. label Apr 17, 2022
@davidye
Copy link
Author

davidye commented Apr 17, 2022

OK - I was able to fix this issue by deleting ~/.next. Seems like a build cache bug. Latest version removed routing-items.js but cached build files still require it?

@switz
Copy link

switz commented Apr 19, 2022

OK - I was able to fix this issue by deleting .next. Seems like a build cache bug. Latest version removed routing-items.js but cached build files still require it?

+1 this fixed it for me, thanks.

@timneutkens
Copy link
Member

Did you upgrade Next.js while running the app and didn't reboot after upgrading? Just trying to figure out how to reproduce this.

@davidye
Copy link
Author

davidye commented Apr 20, 2022

I'm not sure whether Next.js was running during the npm install. But afterwards, restarting with next -p 8080 would fail with this error. Tried upgrading / downgrading several times and this only resolved after I removed .next.

@timneutkens
Copy link
Member

That's quite unexpected as the Next.js version is part of the cache key which would mean that any up/downgrade would invalidate the cache.

@D-Pagey
Copy link
Contributor

D-Pagey commented Apr 21, 2022

OK - I was able to fix this issue by deleting ~/.next. Seems like a build cache bug. Latest version removed routing-items.js but cached build files still require it?

Had the same issue and this fixed for me as well 👍

@davidye
Copy link
Author

davidye commented May 3, 2022

That's quite unexpected as the Next.js version is part of the cache key which would mean that any up/downgrade would invalidate the cache.

It's happened again upon upgrading to 12.1.6

Error: Cannot find module 'next/dist/server/denormalize-page-path.js'

This time I've backed up the problematic ~/.next folder. Let me know if I can help provide additional debugging.

@untitledlt
Copy link

Error: Cannot find module 'next/dist/server/denormalize-page-path.js'

I'm getting the same error.
Downgraded to 12.1.5 until this will be fixed.

@timneutkens
Copy link
Member

This will most likely be fixed in #36666, just published a new canary version that has that PR: https://github.com/vercel/next.js/releases/tag/v12.1.7-canary.3

@Alexolo
Copy link

Alexolo commented May 9, 2022

Error: Cannot find module 'next/dist/server/denormalize-page-path.js'

I'm getting the same error. Downgraded to 12.1.5 until this will be fixed.

I had the same error. But for me it was due to having "next": ^12.1.5" in my package.json and not including a lock-file when building from the dist-folder, so the resulting build used "12.1.6" instead.
Locking to 12.1.5 solved it, and I'm looking into copying the lock-file from my monorepo as a build-step to mitigate such issues.

@Brendan-33
Copy link

Brendan-33 commented Jun 4, 2022

Error: Cannot find module 'next/dist/server/denormalize-page-path.js'

Similar to @Alexolo ...

Resolved by changing package.json and package-lock.json references to next from 12.1.6 to 12.1.5.

And then deleting node_modules and npm i all packages again.

@Okpainmo
Copy link

Simply deleting the .next folder and running the server afresh("pnpm run dev") resolved the issue for me.

@Isaac-Tait
Copy link

Isaac-Tait commented Oct 17, 2022

I was also getting a similar error message:

error - Error: Cannot find module 'next/dist/shared/lib/router/utils/is-bot.js'

I tried downgrading next from 12.1.6 to 12.1.4 but then I was getting this error message:

error - Error: Cannot find module 'next/dist/shared/lib/router/utils/remove-trailing-slash.js'

To note when I opened localhost:3000 I would get the error message: TypeError: Cannot read properties of null (reading 'useContext')

So, I deleted .next and afterward I was able to run yarn dev without triggering the error.

EDIT: When I ran yarn add next@latest I upgraded to 12.3.1 and the same errors came back. Downgrading to 12.1.4 and deleting .next did not clear it either... More debugging is needed on my end I guess.

EDIT EDIT:: So, I think it is an issue with my cache. I cloned the repo and after running yarn install I had no problems with the errors cropping up. I am using Next 12.1.6 in the "fresh" clone. I know Gatsby has the command gatsby clean to wipe a cache - does Next have something similar?

@erwanvivien
Copy link

erwanvivien commented Oct 18, 2022

I have the error that @Isaac-Tait mentionned

I'm using next: 12.3.0 and it is only when in production mode that the error triggers (In a Docker container, so no errors with .next or node-modules)

EDIT: Upgrading to 12.3.1 fixed the issue for me

@engineergit
Copy link

@davidye I am facing same error as you mentioned :
Just deleting the .next folder and running npm start again has fixed the issue for me

@SnowzyTech
Copy link

OK - I was able to fix this issue by deleting ~/.next. Seems like a build cache bug. Latest version removed routing-items.js but cached build files still require it?

OK - I was able to fix this issue by deleting ~/.next. Seems like a build cache bug. Latest version removed routing-items.js but cached build files still require it?

Thanks, man this saved a life!

@ameshkin
Copy link

Appears as if the new raw blitz app is broken. I am unable to get it working even after deleting .next and node modules folders

@ZeeshanAhmadKhalil
Copy link

ZeeshanAhmadKhalil commented Jul 24, 2023

Getting this issue when deployed to AWS elastic Beanstalk:

Error: Cannot find module 'next/dist/server/future/route-modules/route-module.js'
Jul 24 09:37:53 ip-172-31-85-238 web: Require stack:
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/.next/server/pages/_app.js
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/node_modules/next/dist/server/require.js
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/node_modules/next/dist/server/next-server.js
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/node_modules/next/dist/server/next.js
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/node_modules/next/dist/server/lib/start-server.js
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/node_modules/next/dist/cli/next-start.js
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/node_modules/next/dist/lib/commands.js
Jul 24 09:37:53 ip-172-31-85-238 web: - /var/app/current/node_modules/next/dist/bin/next

On my local PC yarn start works find. But on AWS its gives issue.

Next version: ^13.1.6

@luohao123
Copy link

Same issue here, didn't have any ~/.next folder, delete .next in project root didn't help.

@Daidalos117
Copy link

Getting this issue when brand new project generated by blitz new.

@colburncodes
Copy link

colburncodes commented Oct 16, 2023

I had the same issue running npm i next@latest react@latest react-dom@latest eslint-config-next@latest after creating my project addressed the issue. @Daidalos117

@Unsleeping
Copy link

i changed it to "next/dist/shared/lib/app-router-context.shared-runtime" on next version "next": "14.1.0", and this helped me

@samcx
Copy link
Member

samcx commented Feb 28, 2024

Closing this since there is no :repro: for this!

@samcx samcx closed this as completed Feb 28, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests