Skip to content
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

Unsupported: TypeScript 3.8 Syntax: import type #11909

Closed
balupton opened this issue Apr 15, 2020 · 11 comments
Closed

Unsupported: TypeScript 3.8 Syntax: import type #11909

balupton opened this issue Apr 15, 2020 · 11 comments
Assignees
Milestone

Comments

@balupton
Copy link

Bug report

Describe the bug

Using the import type syntax from TypeScript 3.8 causes a build failure with next.js

To Reproduce

  1. git clone https://github.com/balupton/nextjs-typescript-3.8-syntax (applies this changeset balupton/nextjs-typescript-3.8-syntax@53a7fc6 to the with-javascript next.js example)
  2. cd nextjs-typescript-3.8-syntax
  3. yarn install
  4. yarn build
yarn run v1.22.4
$ next build
Creating an optimized production build  

Failed to compile.

/Users/balupton/Projects/experiments/nextjs-typescript-3.8-syntax/my-app/pages/index.tsx
ERROR in /Users/balupton/Projects/experiments/nextjs-typescript-3.8-syntax/my-app/pages/index.tsx(3,13):
3:13 '=' expected.
    1 | import Link from "next/link";
    2 | import Layout from "../components/Layout";
  > 3 | import type { AllKeys } from "simplytyped";
      |             ^
    4 | 
    5 | const IndexPage = () => (
    6 |   <Layout title="Home | Next.js + TypeScript Example">


> Build error occurred
Error: > Build failed because of webpack errors
    at build (/Users/balupton/Projects/experiments/nextjs-typescript-3.8-syntax/my-app/node_modules/next/dist/build/index.js:13:900)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior

It to work fine

Screenshots

Screen Shot 2020-04-15 at 6 54 10 pm

System information

Additional context

n/a

@balupton
Copy link
Author

balupton commented Apr 15, 2020

Babel has already landed support for this with babel/babel#11171

Work in eslint is ongoing typescript-eslint/typescript-eslint#1436

As next uses babel I would have thought this would have been sorted.

However, it seems that next is pinned to v7.0.0 of babel — https://github.com/zeit/next.js/blob/92dac596304a3a04c97a7ce40eea722880c79e89/package.json#L55 — which isn't https://github.com/babel/babel/releases/tag/v7.9.2 (bugfix on v7.9.0) or https://github.com/babel/babel/releases/tag/v7.9.0 (initial support)

@johnrjj
Copy link

johnrjj commented Apr 16, 2020

#11840

@Timer Timer added this to the 9.3.6 milestone Apr 22, 2020
@Timer Timer self-assigned this Apr 22, 2020
@Timer Timer modified the milestones: 9.3.6, 9.3.x Apr 28, 2020
@Timer
Copy link
Member

Timer commented Jun 8, 2020

This has been fixed by us upgrading Babel.

See https://github.com/vercel/next.js/tree/canary/examples/with-typescript-types

@Timer Timer closed this as completed Jun 8, 2020
@Timer Timer modified the milestones: 9.x.x, june 2020 Jun 8, 2020
@adamsoffer
Copy link
Contributor

Heads up, I'm still unable to use the import type syntax. When I deploy the with-typescript-types I still get that error. cc @Timer

@tamj0rd2
Copy link

tamj0rd2 commented Jul 3, 2020

I still get this error with the latest version of nextjs (9.4.4)
image

@aasili-shoprunner
Copy link

I'm experiencing the same as @tamj0rd2 when using Next.js 9.4.4 and Typescript 3.9.6

@cvolant
Copy link
Contributor

cvolant commented Aug 27, 2020

Really strange. I hit the same issue, but... I just cannot figure where it comes from.
I my working repo, it works fine, but on the server it failed. So I git-cloned it locally, and with the same branch, same version, it fails with the above error. I ended up with 3 local repositories: 2 are working, 1 is still failing.
So with the same code from my part, in some repo it fails, but in others (on the same computer!)... it works.
😵

@cvolant
Copy link
Contributor

cvolant commented Aug 28, 2020

After some hours (like many hours), I just tried the with-typescript-types exemple in the Next repo. At first I though it worked because yarn next works. But after half a day of further investigations, I came back to the bare example and tried yarn next build, and it failed with the above issue.

Yes, I could have avoided this wasted half a day of investigation if I had read this thread more carefully and noticed the problem was experienced when building, but it was the nth I read 😩, and since the issue was closed, I didn't gave it enough attention.

@Timer, could you reopen it? Babel upgraded or not, it is not fixed yet.

@Cleberw3b

This comment has been minimized.

@Toolo
Copy link

Toolo commented Oct 9, 2020

I think I found the cause:

Support for import type was introduced in @babel/core: 7.9.0 source

However, @babel/core is pinned to v7.7.7 in https://github.com/vercel/next.js/blob/canary/packages/next/package.json#L63

Probably this version would need to be bumped for it to work

CC @Timer

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants