-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
[NEXT-671] Next.js 13.2.1 - Module '"next/navigation"' has no exported member 'usePathname'. #46360
Comments
Same issue with useSearchParam. Here's my code:
Was working with NextJS 13.1, not working anymore after the update to Next 13.2. @TadejPolajnar how did you solve the error exactly? It doesn't work to add a I hope this helps. |
@lionelrudaz you need to insert it right before the problematic row, here is an example: import Image from 'next/image'
import { useMemo } from "react";
// @ts-ignore
import { usePathname } from 'next/navigation'; |
@TadejPolajnar it works as a temporary fix :) |
make sure navigation types is exist in next-env.d.ts
|
@ooyay |
Based on a review I received on proposed PR, this is expected behavior. |
I don't know, but the error was coming up until this line comes |
I'm still getting this error in my App directory project... don't think this is fixed. 13.2.1 |
I can also confirm that I'm also getting this issue when upgrading to 13.2. My project is an app directory project as well. I don't think this issue should be closed. |
Module parse failed: Unexpected token (6:5) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. |
Also seeing this issue in the app directory in 13.2. @TadejPolajnar I would suggest reopening. |
So it looks like the OP's issue is that they are trying to use |
We are using the |
It seems like |
Also having this issue, indeed the issue seems to be that the next-env.d.ts is not updated in the linting proces. 42:11 Error: Unsafe assignment of an `any` value. @typescript-eslint/no-unsafe-assignment
42:22 Error: Unsafe call of an `any` typed value. @typescript-eslint/no-unsafe-call |
In order to get the update to the types, you have to run /// <reference types="next/navigation-types/navigation" />
/// <reference types="next/navigation-types/compat/navigation" /> This was changed in #45919 to ensure that users who are using both |
I know this is the fix for development and actually works, but A possible solution is to also generate the file in a |
Close this prematurely! Going to keep it open to see if we can smooth this or not. |
Hey! im on 13.2.1 and even after running next dev my declaration file does not set these type declarations lines by default I have already tried to remove node_modules and re-install packages, but the issue persists. Am i doing something wrong? Cuz i saw some comments that running the development server fixed the issue by adding those reference lines Im not using the app directory, im using the pages directory, maybe is something related? edit: i started a new project, and the declaration file is created with the correct references, seems like the problem is with the pages directory? after running next dev this is the file generated:
|
Since both
Fixing this during linting is already tracked here #46104. (There is also a PR #46249)
Exactly. This type is generated only when |
Oh! i missed this comment, my bad! So, the solution for that is to refactor the project to use the app directory or lock next in 13.1.6? |
If you're not using app directory @giovanedann, then you should continue to use |
@wyattjoh sure, appreciate your time! Thank you very much! @balazsorban44 |
This might be a long shot here, but I get this exact same error message when I tried using turborepo in their monorepo configuration. I had ui components in a separate package folder, however, those ui components needed useSearchParams and usePathname. Is my only option as of right now is to use |
Just want to add: This doesn't occur for me with #46249 generates Best way would be to have an explicit way to generate |
Also running into this issue when upgrading from next 13.1.6 to 13.2.1 without changing anything else.
is set correctly after running Should next/navigation always been used when using the app directory or should next/router be used when using the router outside of the app directory? |
* feat(router-picker): add a context value for legacy and new router switch * feat(routing): rename router to `legacy-router` * feat(router): add new router context * feat(router): update router bindings types * feat(resource): update resource types in bindings * refactor(resource): memoize values inside context * feat(core): update refine wrapper with new router * chore(querykeys): nullable id in detail * chore(exports): update router exports as legacy * chore(exports): export resource context * test(mocks): update to legacy router * feat(helpers): add legacy transform for resources * chore(helpers): add resource sanitize helpers * chore(pick-resource): add pick resource helper * chore(redirect): handle undefined cases * chore(route-generator): update legacy helper * chore(router): add route matching and generation helpers * feat(router): add new way of route matching helpers * feat(react-router-v6): update bundle config for `/legacy` exports * chore(react-router-v6): export legacy router from `/legacy` subpath * feat(react-router-v6): add `<RefineRoutes />` component * feat(react-router-v6): add and export bindings * chore(use-navigation): update hook for backward compability and internal use * feat(router): add new router hooks and deprecate legacy * feat(router): update redirection logic in form * feat(router): update use-resource with new bindings * feat(router): update use breadcrumb for new bindings * feat(use-table): update sync with location with new bindings * chore(router): update hooks for undefined resources * test(examples): add test setup for new router bindings * chore(codemod): add router to legacy router codemod * chore(router): add missing exports * feat(codemod): add legacy router option * test(examples): transform all to legacy router * feat(ui-types): add `meta` to buttons * chore(ui-types): remove deprecated access control prop * feat(remix): add new bindings and move to legacy * feat(react-router-v6): update bindings with components * feat(nextjs): move existing routers to legacy * feat(nextjs): add new router bindings for app and pages * feat(core): add `link` to router bindings * feat(core): add new useResource overload * feat(core): update hooks with new bindings * feat(core): add `useToPath` and `useLink` hooks * feat(antd): update components with new router bindings * feat(codemod): update legacy router transformation for all * feat(codemod): add move-deprecated-access-control transformation * feat(codemod): rename to legacy router provider prop * test(inferred-params): add inferred params test * test(core-router): add router helper unit tests * refactor(core): update use-resource usage * chore(core): remove deprecated props * feat(antd): update with new routing * feat(chakra): update with new routing * feat(mantine): update with new routing * feat(mui): update with new routing * feat(hook-form): update with new routing * feat(kbar): update with new routing * chore(inferencer): update with deprecated values * chore(core): remove warnings * test(core): update test wrapper for routers * feat(react-router-v6): add show segment * feat(core): add show segment to default paths * test(core): update hook tests for routers * feat(core): update `useMenu` * chore(core): update type export * chore(core): update route composer * feat(core): update auth hooks for new routing * feat(core): add redirect with new router in authenticated component * chore(core): fix backward compatibly * test(core): fix auth hook tests * chore(core): remove unused mocks * chore(core): remove `react-router-dom` from devDeps * fix(remix): move `qs` to deps * feat(router): add unsaved-changes-notifier comps * feat(core): deprecate layout props * chore(core): replace params to meta * feat(ui): add `meta` to breadcrumbs * fix(core): update router bindings * feat(core): create route on legacy even if not exists * chore(core): replace type export * test(core): transform resources at tests * test(ui-tests): update router * test(core): remove `fit` * test(ui-tests): update button tests * chore(core): allow deprecated options in meta * fix(core): check for route in legacy * fix(antd): update selected key in antd sider * test(antd): update test setup * fix(mui): selectedKey in sider * fix(mui): fix broken show title * fix(core): legacy resource can be undefined * test(mui): update test setup * fix(chakra-ui): variable name * test(chakra-ui): update test setup * fix(mantine): update sider key * test(mantine): update test setup * chore(core): fix lint error * fix(core): update conflicting types * fix(live-previews): rename to legacy * chore(examples): remove obsolete props * test(inferencer): update test setup * test(inferencer): update snapshots * test(ui-tests): fix clone button tests * test(kbar): fix test setup * chore(react-router-dom): upgrade version * fix(react-router-v6): remove unused argument * fix(react-router-v6): fix legacy looping * chore(examples): remove unused import * chore(examples): rename `routerProvider` prop * chore(react-location): mark as private * build: ignore refine-react-location at bootstrapping * build(codemod): fix versions * fix(codemod): update to matching versions * build: remove codemod case * chore(examples): fix undefined error * chore(examples): fix import path * chore(examples): update react-router imports * chore(examples): update `Link` * fix(codemod): add export rename for routers * build(codemod): add `start` script * chore(examples): fix export paths * chore(examples): add fallback * fix(core): use menu return type * chore: exclude react-location * chore(react-location): fix type error * chore: update bootstrap script * chore(examples): fix unknown prop name * chore(examples): fix unexported import * fix(core): useIsAuthenticated hook * fix(core): `Authenticated` component * test(core): update tests * test(react-table): add resource * test(antd): add route inference * test(auth): fix test setups * fix(core): handle undefined return in query function * fix(react-router-v6): skip authentication if not provided * refactor(core): move `patname` in bindings to response * fix(core): authenticated component calls * fix(core): do not include parent prefix in new routing system * fix(core): use table link creation with new routing * fix(core): always pick parent in breadcrumb * fix(antd): use link by router type * feat(sider): add `meta` to sider for menu creation * chore(examples): add new routing example * fix(core): allow additional nested params in parse * feat(core): add form sync with location param type * fix(core): remove console * feat(antd): add `syncWithLocation` to `useDrawerForm` * feat(antd): add `syncWithLocation` to `useModalForm` * feat(mantine): add `syncWithLocation` to `useModalForm` * feat(hook-form): add `syncWithLocation` to `useModalForm` * chore(examples): note `routerBindings` as optional * feat(remix): add `navigate-to-resource` component * fix(nextjs): fix multiple calls in NavigateToResource * refactor(syncWithLocation): use `identifier` when possible * chore(examples): fix lint issue * test(core): parent prefix on legacy and new * chore(examples): remove commented authProvider * chore(examples): fix wrong name * chore(core): remove deprecation mark * fix(react-router-v6): better workaround for usePrompt * fix(core): remove repeated params * fix(nextjs-router): type issue (vercel/next.js#46360) * fix(nextjs): pathname issue * fix(nextjs): wait for router to settle * chore(live-previews): move demo components to legacy router * chore(core): warn users for unknown properties in router provider * chore: add changesets * chore(core): add `identifier` * chore(kbar): add changeset * chore(examples): upgrade `with-nextjs-auth` * chore(changeset): update changesets * chore(examples): fix legacy type import * chore(examples): fix build changes * feat(live-previews): add react-router-dom * chore(live-previews): add memory router replacement
Hi, this has been updated in the latest canary of Next.js, please update and give it a try! |
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. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue
https://stackblitz.com/edit/nextjs-q4nrme?file=package.json,tsconfig.json,pages%2Findex.tsx
To Reproduce
Describe the Bug
Hook usePathname works as expected, it returns current path name however typescript throws an error which doesn't allow you to build the page.
Typescript error:
Module '"next/navigation"' has no exported member 'usePathname'.
As a temporary solution I used
// @ts-ignore
to suppress the error for now.Expected Behavior
Typescript type of
usePathname
needs be exported correctly and typescript error should disappear.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
From SyncLinear.com | NEXT-671
The text was updated successfully, but these errors were encountered: