question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Receiving client error when using `pageExtensions` in next.config.js

See original GitHub issue

Hi @KATT, thank you and all the contributors for your hard work with this library. I am running into the following issue.

Issue

After cloning the examples-next-prisma-starter repo, and setting pageExtensions in next.config.js, and running npm run dx I receive the following error:

image

trpc version(s):

How to replicate

  1. clone https://github.com/trpc/examples-next-prisma-starter
  2. update the next.config.js file to the following:
/**
 * @link https://nextjs.org/docs/api-reference/next.config.js/introduction
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  pageExtensions: ['page.tsx'],
  reactStrictMode: true,
};

module.exports = nextConfig;
  1. Change the name of pages/index.tsx to pages/index.page.tsx
  2. Start the application by running npm run dx
  3. Navigate to the application in your browser

Note: I am adding the .page. extension to my pages in order to have my .test files adjacent to my page files. Next attempts to build the test file unless I follow the fix posted here: https://www.reddit.com/r/nextjs/comments/lm0soy/any_way_to_omit_test_files_from_the_build_process/

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
timcolecommented, Jan 22, 2022

Hey there! Looking at the docs on next.js for this they have a note on there

Note: Make sure you also rename _document.js, _app.js, _middleware.js, as well as files under pages/api/.

Just tested it and adding .page.tsx to the following files: src/pages/_app.tsx, src/pages/index.tsx, src/pages/post/[id].tsx and adding something like api.ts to your pageExtensions so you can rename src/pages/api/trpc/[trpc].ts to something like [trpc].api.ts should solve this for you.


Basically this 😃

renamed:    src/pages/_app.tsx -> src/pages/_app.page.tsx
renamed:    src/pages/api/trpc/[trpc].ts -> src/pages/api/trpc/[trpc].api.ts
renamed:    src/pages/index.tsx -> src/pages/index.page.tsx
renamed:    src/pages/post/[id].tsx -> src/pages/post/[id].page.tsx
pageExtensions: ['page.tsx', 'api.ts']
2reactions
reggie3-braingucommented, Jan 22, 2022

@timcole Thanks! That did the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Page Extensions - next.config.js
Extend the default page extensions used by Next.js when resolving pages in the pages directory. ... Inside next.config.js , add the pageExtensions config:...
Read more >
pageExtensions not respecting file extension #6878 - GitHub
If I provide next.config.js a pageExtensions value of pageExtensions: ['tsx'] I am having pages created for non-tsx pages. To Reproduce.
Read more >
Error of build because of the error Module parse failed
After the commannd npm run build I'm getting the following error. warn - Invalid next.config.js options detected: - The root value has an ......
Read more >
8.0.3 - next - npm
jsonPageRes - Fetch Response object (client only); err - Error object if any error is encountered during the rendering. Routing. Next.js does ...
Read more >
Development-only pages in Next.js - DEV Community ‍ ‍
Build pages in Next.js that are only viewable in a development environment ... site by getting creative with Next's pageExtensions setting.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found