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.

No TypeScript error overlay in development after updating to 9.4

See original GitHub issue

Bug report

I updated nextjs from 9.3.6 to 9.4.0.

Describe the bug

After updating I do not get typescript errors anymore checked during buildtime. This was working in 9.3.6.

To Reproduce

As I have quite a complex mono repository, I’m unable to provide the source of that. Major differences to a stock configuration is a custom babel configuration:

module.exports = {
  presets: [],
  plugins: [
    'lodash',
    '@babel/proposal-class-properties',
    'react-intl-auto',
    'babel-plugin-graphql-tag'
  ],
  env: {
    test: {
     presets: [
       '@babel/typescript',
         [ '@babel/preset-env',
           {
           targets: {
             node: process.versions.node
           }
         }
         ],
       '@babel/preset-react'
     ]
    },
    nodeTs: {
      presets: [
        '@babel/typescript',
        '@babel/preset-react',
        [
          '@babel/preset-env',
          {
            targets: {
              node: process.versions.node
            }
          }
        ]
      ]
    },
    nextjs: {
      presets: ['next/babel']
    }
  }
}

And a custom next.config.ts:

/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')

const withDevTool = (nextConfig: any = {}) => {
  return {
    ...nextConfig,
    webpack(config: any, options: any) {
      const { dev } = options
      if (dev) {
        config.devtool = 'eval-source-map'
      }
      if (typeof nextConfig.webpack === 'function') {
        return nextConfig.webpack(config, options)
      }
      return config
    },
  }
}

export default () => {
  const optimizedImages = require('next-optimized-images')

  const withTM = require('next-transpile-modules')([
    'query-string',
    'imask/esm',
   /** ..some more private modules */
  ])

  const withCustomBabelConfigFile = require('next-plugin-custom-babel-config')
  const withCSS = require('@zeit/next-css')

  const withBundleAnalyzer = require('@next/bundle-analyzer')({
    enabled: process.env.ANALYZE === 'true',
  })

  return withDevTool(
    withBundleAnalyzer(
      optimizedImages(
        withCustomBabelConfigFile(
          withCSS(
            withTM({
              babelConfigFile: path.resolve(
                path.join(__dirname, '../../../../babel.config.js')
              ),
              distDir: 'dist',
            })
          )
        )
      )
    )
  )
}

I’m using a custom server with additional express middleware.

// This file doesn't go through babel or webpack transformation.
// Make sure the syntax and sources this file requires are compatible with the current node version you are running
// See https://github.com/zeit/next.js/issues/1245 for discussions on Universal Webpack or universal Babel
import 'dotenv/config'
import express from 'express'
import next from 'next'
import { defaultMiddleware } from '../index'
import { appConfig } from './appConfig'

const applicationFactory = (): void => {
  const dev = process.env.NODE_ENV !== 'production'
  const conf = dev
    ? // eslint-disable-next-line @typescript-eslint/no-var-requires
      require('./next.config').default()
    : {
        distDir: 'dist',
      }
  const app = next({
    dev,
    conf,
  })
  const handle = app.getRequestHandler()
  app.prepare().then(() => {
    const server = express()
    const proxyInstance = defaultMiddleware(server, appConfig)
    server.get('*', (req, res) => {
      return handle(req, res)
    })
    const port = process.env.PORT || 3000
    // @ts-ignore
    const listener = server.listen(port, (err: Error) => {
      if (err) {
        throw err
      }
      // tslint:disable-next-line:no-console
      console.log(`> Ready on http://localhost:${port}`)
    })
    listener.on('upgrade', (req: any, socket: any, ...rest: any) => {
      socket.on('error', (error: any) => {
        console.error(error)
      })
      proxyInstance.upgrade(req, socket, ...rest)
    })
  })
}

export default applicationFactory

Expected behavior

Typescript errors should be reported.

System information

  • OS: Windows
  • Version of Next.js: 9.4.0
  • Version of Node.js: 12.13.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

127reactions
vitrukromancommented, Jun 28, 2020

Please add an option to enable typescript checks for the whole code during development

33reactions
Timercommented, May 11, 2020

Hello! This is intended as part of the new Fast Refresh experience. We wanted to make updates visible as fast as possible, without interrupting your train of thought for a type error.

We feel type checking in development is better done passively by your editor!

Plus, we can recover from runtime errors now so it’s not necessary to pass type checking to test your application (a runtime error won’t cause you to lose application state).

Type checking is still performed during your production build.

Read more comments on GitHub >

github_iconTop Results From Across the Web

create react app - Disable error overlay in development mode
When developing error boundary components and styling/testing how they look, this is an extremely annoying feature. It slows down development ...
Read more >
Blog - Next.js 9.4
Development session resumption after a syntax error is fixed, without losing application state; Automatic dismissal of unhandled runtime errors ...
Read more >
How to get an error overlay with React Hot Loader - Jakob Lind
First, make sure you are using version 2.2. 1 of webpack-dev-server. If you don't, upgrade. There are two ways to run webpack-dev-server: With...
Read more >
Fast Reliable/Hot Reloading in Next.js - Coding Ninjas
You'll see a contextual overlay when you make a mistake in your component, leading to a runtime error. If the error is fixed,...
Read more >
What's New | Oracle, Software. Hardware. Complete.
Oracle Linux 8 Server - Developer preview Unbreakable Enterprise Kernel Release 6 ... Oracle Cloud Infrastructure SDK for Typescript and JavaScript (Update) ...
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