Next.js Discord

Discord Forum

API endpoints return HTML instead of JSON

Donskoy posted this in #help-forum
Open in Discord
Hello everyone,

My company interally cusomizes dagster an open source scheduler written in next js. However I run into an issue that I have no solution for

While developing the app I added couple routes in the pages/api destination. While running the application using yarn start which is the equivalent of next dev (hot reloads etc) the routes are working fine and returning the appropriate JSON content.

However when I try to build the app using yarn build while the source code is compiling successfully and the app launches every API route is returning text/html as a response and more specifically the html of index.html file which is the main page.

Here is the next.config.js file for reference
const nextConfig = {
  output: 'export',
  productionBrowserSourceMaps: true,
  basePath: process.env.NEXT_PUBLIC_BASE_PATH,
  transpilePackages: ['@dagster-io/ui-components', '@dagster-io/ui-core'],
  compiler: {
    styledComponents: true,
  distDir: 'build',
  experimental: {
    appDir: false,

module.exports = (phase) => {
    return {
      output: undefined,
      assetPrefix: undefined,
      async rewrites() {
        return {
          fallback: [
              source: '/:path*',
              destination: '/',
  return nextConfig;

I ve also added two screenshots of the same request when the app is running with yarn start and when on production.
Thanks a lot in advance

3 Replies

Rizky 🙃
if you have output: export you are getting the html files build to use in a static enviroment (ie github pages)
i have no idea how well they are meant to wrk with api endpoints
but it is mroe about yout hoster to deal with the output i tould have thought