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.

[canary] built-in type declarations for `next()` missing

See original GitHub issue

Bug report

Describe the bug

Encountered this bug while trying to upgrade the custom-server-typescript example to the latest canary version of Next.js.

When I try to initiate a server in my custom TypeScript server, the built-in TypeScript declarations doesn’t seem to include the exported next() function used to initiate a server.

Before, initiating a next server works like this:

// ./server/index.ts

import * as next from 'next'

// ...
const app = next({ dev })

However, when I try to upgrade to canary and do the same, calling next() gives me this error:

// ./server/index.ts

import * as next from 'next'

// ...
const app = next({ dev }) // Error!
Cannot invoke an expression whose type lacks a call signature. Type 'typeof import("<snip>/node_modules/next/types/index")' has no compatible call signatures.

See “Additional context” for more information. I’ll update this issue as I see more possible fixes.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Upgrade the next package in the mentioned example to latest canary version.
  2. Remove the old @types/next declarations.
  3. Try to import next and initiate a server.
  4. See error.

Expected behavior

  • No type errors when importing the default next module in a TypeScript custom server.
  • Base next module should be typed properly (see declarations on DefinitelyTyped for reference)

Screenshots

Using 8.1.0 + DefinitelyTyped typings:

image

Using canary:

image

System information

  • OS: macOS 10.14.5
  • Browser (if applies): Chrome
  • Version of Next.js: v8.1.1-canary.47

Additional context

It seems like the type declarations passed into package.json (types/index.d.ts) only includes the next/next-server helper types. However, it doesn’t actually include the actual declaration of the next() function that exists on the main file (server/next.js).

Well, we seem to have the declarations for the main file over here, but since we have the types key set in package.json it’s ignored in favour of the declaration file without the next() declaration!

It’s also worth noting that if I import next/dist/server/next directly, the types work as normal.

See declarations on DefinitelyTyped for reference.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
Timercommented, Jul 2, 2019
4reactions
resir014commented, Jun 24, 2019

Turns out I forgot to add this info in the first post. It’s also worth noting that if I import next/dist/server/next directly, the types work as normal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[canary] built-in type declarations for next() missing #7529
It seems like the type declarations passed into package.json (types/index.d.ts) only includes the next / next-server helper types. However, it ...
Read more >
next - npm
Start using next in your project by running `npm i next`. ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >
TypeError: unsupported file type: undefined after update to v ...
It works now as of next@v11.0.1 . No need to follow the steps below. Disable the static images feature for now as a...
Read more >
Release Notes for the WebView2 SDK - Microsoft Learn
Use the Canary preview channel of Microsoft Edge when you develop using a prerelease version of the WebView2 SDK package.
Read more >
Compose UI - Android Developers
Build animations in their Jetpack Compose applications to enrich the user experience. compose.compiler, Transform @Composable functions and enable optimizations ...
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