Skip to content

tsc complains require() file path outside of rootDir only when await import() is used #38611

Closed
@ychi

Description

@ychi

TypeScript Version: 4.0.0-dev.20200516

Search Terms: commonjs, esmodule, rootDir

Code
Consider this file:

onst {version: VERSION} = require('../package.json');
console.log(VERSION);

async function foo() {
    let obj = {};
    console.log(obj);
}

export async function bar() {
    console.log('foo');
    await foo();
}

And this file:

const {version: VERSION} = require('../package.json');
console.log(VERSION);

async function foo() {
    let obj = await import('./anotherFile');
    console.log(obj);
}

export async function bar() {
    console.log('foo');
    await foo();
}

Expected behavior:
Running tsc to compile them, they should both succeed or both fail?
Actual behavior:
The first file can be compiled smoothly, while the second was complained about error TS6059 and error TS6307.
Playground Link: https://glitch.com/~aromatic-bittersweet-biplane

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions