Skip to content

In JS, commonjs require followed by access expression can't import from ES #40185

Closed
@sandersn

Description

@sandersn

For the program

// @filename: main.js
const x = require('ch').x
x
x.grey
// @filename: ch.js
const x = {
  grey: {}
}
export { x }

Expected behavior:

No error, and x: { grey: {} }

Actual behavior:

on const x = require, error that 'x is unused'
on x.grey, error that 'cannot find name x'

Based on a failure from office-ui-fabric in a JS script that uses chalk. (and, notably uses export default, so that needs to be tested too)

Works if you use commonjs exports:

const x = { grey: { } }
module.exports.x = x

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