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.

Typescript: Unable to re-export a type with Webpack 4

See original GitHub issue

I’m submitting a bug report Webpack Version: 4.4.1 Babel Core Version: 7.0.0-beta.44 Babel Loader Version: 8.0.0-beta.0 Please tell us about your environment:

I am using Bable beta with the typescript preset.

In one file, I define and export a type:

// a.ts
export type MyType = "a" | "b";

In another file, I re-export this type:

// b.ts
export { MyType } from "./a.ts";

Current behavior:

The export line is not present when a.ts is compiled using Babel. The re-export line in b.ts is compiled to:

export { MyType } from "./b";

Webpack fails with this error:

    ERROR in ./app/client/utils.ts
    79:0-51 "export 'myType' was not found in './a'
     @ ./b.ts

Expected/desired behavior:

It worked fine with Webpack 3, I am not sure why. babel should not output anything for the re-export but it does. I am not sure why Webpack 3 was not complaining about the issue, but now Webpack 4 does.

I am not sure if this should be filled in this repo, or with Webpack or Babel core. I can provide a repro if this is needed and the correct place for this issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:23
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

34reactions
andy-mscommented, Sep 4, 2018

You can still do are-export if it’s clear that you’re exporting a type:

import { T as a_T } from "./a";
export type T = a_T;

You can also do export * from "./a";.

23reactions
Akiyamkacommented, Mar 20, 2020

@niksumeiko, that cool, but not supported by babel-loader; export type { IGeocoder } from './types'; crush build with Unexpected token error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting error with webpack when using import/export
For webpack to be able to resolve typescript file, you need to add it to the list of webpack extensions. By default, webpack...
Read more >
TypeScript - webpack
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. In this guide we will learn how to integrate TypeScript with...
Read more >
Documentation - TypeScript 3.8
TypeScript 3.8 adds a new syntax for type-only imports and exports. ... When using import type to import a class, you can't do...
Read more >
type-only imports — A new TypeScript feature that benefits ...
How should Babel handle those imports and exports? ... This allows you to use Babel for all of its benefits, while still being...
Read more >
Leveraging Type-Only imports and exports with TypeScript 3.8
A few months back, I started seeing strange warnings in Webpack about exports that couldn't be found. After digging for a little while...
Read more >

github_iconTop Related Medium Post

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 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