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

SyntaxError: Named export 'useParams' not found #33

Open
AlejandroYanes opened this issue Dec 19, 2023 · 17 comments
Open

SyntaxError: Named export 'useParams' not found #33

AlejandroYanes opened this issue Dec 19, 2023 · 17 comments

Comments

@AlejandroYanes
Copy link

AlejandroYanes commented Dec 19, 2023

Hi, am trying to setup the speed-insights module on the pages directory but I get this error

Server Error
SyntaxError: Named export 'useParams' not found. The requested module 'next/navigation.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'next/navigation.js';
const { useParams, usePathname, useSearchParams } = pkg;

Stack:

  • turbo v1.11.1
  • React v18.2.0
  • TypeScript v4.9.4
@mayankmmmx
Copy link

Also facing this same issue.

@praveentcom
Copy link

Facing the issue as well during runtime.

import { useParams, usePathname, useSearchParams } from "next/navigation.js";
         ^^^^^^^^^
SyntaxError: Named export 'useParams' not found. The requested module 'next/navigation.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'next/navigation.js';
const { useParams, usePathname, useSearchParams } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15) {
  page: '/sso/[...slug]'
}

@azhong-git
Copy link

+1

@AlejandroYanes
Copy link
Author

I think it has to do with this file. I tried doing the import the same way on one of my components and it works fine but if I add the <SpeedInsights /> component to the _app.tsx then my own component's import also fails

@arenclissold
Copy link

arenclissold commented Dec 21, 2023

I have a similar issue when adding <SpeedInsights /> to _app.tsx but only for specific pages, also getting some hydration errors on other pages.

Error: Cannot find module 'next/dist/server/future/route-modules/pages/vendored/contexts/app-router-context'

@aaalloc
Copy link

aaalloc commented Jan 3, 2024

This problem hasn't still been fixed ...

@SaranshChaudhary
Copy link

+1

@tobiaslins
Copy link
Collaborator

Hey all!

I just tried to reproduce with Next.js 14.0.4 & pages router and with & without turbo and couldn't reproduce this.

Can someone please create us a minimal reproduction repository to further dig into this?

Thanks!

@aaalloc
Copy link

aaalloc commented Jan 11, 2024

Hey all!

I just tried to reproduce with Next.js 14.0.4 & pages router and with & without turbo and couldn't reproduce this.

Can someone please create us a minimal reproduction repository to further dig into this?

Thanks!

I was on a version below 14 for my case and updating to last version (14.0.4) fixed the issue !

@huozhi
Copy link
Member

huozhi commented Jan 11, 2024

This is not a valid import as next/navigation doesn't have default export so pkg will end up as undefined.

import pkg from 'next/navigation.js';
const { useParams, usePathname, useSearchParams } = pkg;

We landed some bundling improvements about handling Next.js APIs fully specified imports with extensio, such as next/navigation.js. Could you also try upgrading to canary to see if it works for you?

If it still error, could someone provide a minimal reproduction that it failed on deployment? I'll help take a look. Thanks 🙏

@AlejandroYanes
Copy link
Author

AlejandroYanes commented Jan 11, 2024

I switched my app to the app directory and it's working fine now. I will leave this issue open for other people using a version bellow 14

@AlejandroYanes
Copy link
Author

This is not a valid import as next/navigation doesn't have default export so pkg will end up as undefined.

import pkg from 'next/navigation.js';
const { useParams, usePathname, useSearchParams } = pkg;

We landed some bundling improvements about handling Next.js APIs fully specified imports with extensio, such as next/navigation.js. Could you also try upgrading to canary to see if it works for you?

If it still error, could someone provide a minimal reproduction that it failed on deployment? I'll help take a look. Thanks 🙏

This wasn't an import I did, it's one from one of the internal packages of the <SpeddInsights />, this file

@feugy
Copy link
Member

feugy commented Jan 16, 2024

@mayankmmmx, @SaranshChaudhary, @arenclissold, @azhong-git, @praveentcom, would you mind sharing the exact Next.js version you're using?
This bug should be gone with version 13.3 and others already confirmed that versions 14 and upward are working.

@SaranshChaudhary
Copy link

@feugy - We are using 13.2.1

@Ilya-Valasiuk
Copy link

@SaranshChaudhary Please take a look at configuration. For NextJS version that older 13.3 you should use this config
image

@praveentcom
Copy link

No luck yet. The project is on turbo-repo and have bumped it to [email protected]. It's still throwing the same useParams import error.

Note that there are certain dependencies which are still running 13.1.x and ^13.3+, and I am not sure if these are creating a cascading effect.

Nevertheless, it works when using speed-insights/react import with route attribute.

@feugy @Ilya-Valasiuk

@snairsumith
Copy link

Check out the document carefully. Create a separate component for versions of Next.js older than 13.3.
URL for reference : https://vercel.com/docs/speed-insights/quickstart#add-the-speedinsights-component-to-your-app
Screenshot 2024-08-08 at 11 37 02 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests