Typescript: Unable to resolve files from ones that export both types and variables
- Dominant language
- JavaScript
- Stars
- 4.8k
- Forks
- 456
- Avg merge
- 9h 19m
- Merged PRs (30d)
- 2
Description
**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:
```typescript
// 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
Contributor guide
Assessment
This issue has not been assessed yet.