Skip to content

[Bug]: Can't find source file when using custom page extensions #2072

@RohitRajendran

Description

@RohitRajendran

Summary

When using the custom page extensions setting for Next.JS, you'll see errors during the onBuild event saying that it could not find the source file for your api routes. This causes things like scheduled functions not to work.

image

Steps to reproduce

  1. Create a Next.JS project with the custom page extensions setting set.
const nextConfig = {
  pageExtensions: ['page.tsx', 'api.ts'],
}
  1. Create an api route that uses the scheduled function feature
  2. Deploy and check the build logs

A link to a reproduction repository

No response

Next Runtime version

4.36.0

Is your issue related to the app directory (beta)?

  • Yes, I am using the app directory

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

None

Your netlify.toml file

`netlify.toml`
# Paste content of your `netlify.toml` file here

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

/** @type {import('next').NextConfig} */

/* eslint-disable @typescript-eslint/no-var-requires */
const { withSentryConfig } = require('@sentry/nextjs');
const withRoutes = require('nextjs-routes/config')({
outDir: 'src/types',
});

const securityHeaders = [
{
key: 'X-DNS-Prefetch-Control',
value: 'on',
},
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'Referrer-Policy',
value: 'origin-when-cross-origin',
},
];

const nextConfig = {
pageExtensions: ['page.tsx', 'api.ts'],
async headers() {
return [
{
// Apply these headers to all routes in your application.
source: '/:path*',
headers: securityHeaders,
},
];
},
sentry: {
// Use hidden-source-map rather than source-map as the Webpack devtool
// for client-side builds. (This will be the default starting in
// @sentry/nextjs version 8.0.0.) See
// https://webpack.js.org/configuration/devtool/ and
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map
// for more information.
hideSourceMaps: true,
},
};

module.exports = async () => {
/**

  • @type {import('next').NextConfig}
    */

const plugins = [
withRoutes,
(config) =>
withSentryConfig(config, {
silent: true,
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
}),
];

return plugins.reduce((acc, next) => next(acc), nextConfig);
};

Builds logs (or link to your logs)

https://app.netlify.com/sites/should-i-refinance-yet/deploys/6449ea55ba1d0d000889878e

Function logs

Function logs
# Paste logs here

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.

Metadata

Metadata

Assignees

Labels

type: bugcode to address defects in shipped code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions