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

Typescript: Unable to resolve files from ones that export both types and variables #769

Open
bpander opened this issue Feb 23, 2019 · 0 comments

Comments

@bpander
Copy link

bpander commented Feb 23, 2019

I'm submitting a bug report

Webpack Version:
4.x

Babel Core Version:
7.x

Babel Loader Version:
8.0.x

Please tell us about your environment:
OSX 10.x

Current behavior:
babel-loader is unable to resolve d.ts files when:

they're re-exported from a file
and that file also exports variables
and those variables are imported AND read in another file

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.

I created a repo to illustrate this issue: https://github.com/bpander/babel-loader-issue

  1. Create a file (File A) that re-exports some typescript types (e.g. export * from './types/Something') as well as variables (e.g. export const foo = 'bar').
  2. In another file (File B), import * from File A.
  3. Observe babel-loader has no issues building.
  4. In File B, read a variable from the import (e.g. with console.log).
  5. Observe babel-loader cannot resolve the re-exported types.

For example:

// FileA.ts
export * from './types/Something';
export const foo = 'bar';

// FileB.ts
import * as lib from './FileA';

const s: lib.Something = { k: 'v' };
console.log(s);

// Commenting out next line will "fix" babel-loader
console.log(lib.foo);

The above code results in the following error when compiled with babel-loader, but not babel or tsc.

ERROR in ./src/lib/index.ts
Module not found: Error: Can't resolve './types/Something' in '/Users/home/Code/babel-loader-issue/src/lib'
 @ ./src/lib/index.ts 1:0-34 1:0-34
 @ ./src/index.ts

What is the expected behavior?
babel-loader matches the behavior of babel and typescript and is able to resolve the file.

What is the motivation / use case for changing the behavior?
If something compiles in both typescript and babel, it stands to reason it should compile in babel-loader too.

Possibly irrelevant postscript
This is similar to #603, but I believe this is a distinct issue and one with babel-loader because:

a) in my reduced test case (https://github.com/bpander/babel-loader-issue), I set isolatedModules to true, and typescript still has no issues compiling
b) babel-loader doesn't complain unless you read a variable from the import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant