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

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

Closed
sandersn opened this issue Aug 21, 2020 · 1 comment · Fixed by #40221
Closed

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

sandersn opened this issue Aug 21, 2020 · 1 comment · Fixed by #40221
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@sandersn
Copy link
Member

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
@sandersn sandersn self-assigned this Aug 21, 2020
@sandersn sandersn added the Bug A bug in TypeScript label Aug 21, 2020
@sandersn sandersn added this to the TypeScript 4.1.0 milestone Aug 21, 2020
@sandersn sandersn added this to Not started in Rolling Work Tracking Aug 21, 2020
@sandersn sandersn moved this from Not started to In Progress in Rolling Work Tracking Aug 21, 2020
@sandersn
Copy link
Member Author

The commonjs-specific code for resolving access expressions on require('ch') assumes a fake commonjs export. It needs to call resolveSymbol on a real export since it will be an alias.

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Aug 24, 2020
@sandersn sandersn moved this from In Progress to In Review in Rolling Work Tracking Aug 24, 2020
Rolling Work Tracking automation moved this from In Review to Done Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
Development

Successfully merging a pull request may close this issue.

2 participants