Skip to content

[Bug]: Could not find source file for page /api/ when index file for the folder #2100

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

Closed
3 tasks
RohitRajendran opened this issue May 11, 2023 · 2 comments · Fixed by #2101
Closed
3 tasks
Labels
type: bug code to address defects in shipped code

Comments

@RohitRajendran
Copy link

Summary

When deploying my project, I get "Could not find source file for pages" errors for my routes. I believe this is because my routes are defined as index files in the named folder within the api folder (i.e. /api/analyze/index.api.ts).

The plugin is looking for the file at /api/analyze.api.ts and doesn't seem to be considering that it could be an index file within a folder of that route's name.

Steps to reproduce

  1. Create a Next.JS project that has an api handler located in /api/test/index.ts
  2. Deploy and check the build logs

A link to a reproduction repository

No response

Next Runtime version

4.36.1

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

No response

Your public/_redirects file

No response

Your next.config.js file

`next.config.js`
/** @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)

Build logs

https://app.netlify.com/sites/should-i-refinance-yet/deploys/645c0f59533f0b0007a672fe

Function logs

No response

.next JSON files

No response

@RohitRajendran RohitRajendran added the type: bug code to address defects in shipped code label May 11, 2023
@kodiakhq kodiakhq bot closed this as completed in #2101 May 11, 2023
@pieh
Copy link
Contributor

pieh commented May 11, 2023

Merged your PR. It will be released most likely on Monday - you can follow release PR ( #2097 ) to track if/when it will be released

@RohitRajendran
Copy link
Author

Merged your PR. It will be released most likely on Monday - you can follow release PR ( #2097 ) to track if/when it will be released

Great! Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants