Skip to content

Conversation

@johnsoncodehk
Copy link

@johnsoncodehk johnsoncodehk commented Jun 25, 2019

The '__esModule' is a standard for CommonJS, but forcing the emit '__esModule' does cause problems for many users.

Issues: #30718 #30166 #22879 #15795 #15685 #14351 #13709 (comment)

For me, I have a script that converts the CommonJS code into a baas cloud code, but the Typescript API has no way to remove '__esModule', I can only do replace string of this code:

Object.defineProperty(exports, "__esModule", { value: true });

But this is not safe, I am not sure if Typescript will change this code in the future:

@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary

@msftclas
Copy link

msftclas commented Jun 25, 2019

CLA assistant check
All CLA requirements met.

@YoungNovice
Copy link

good

@gavar
Copy link

gavar commented Jul 27, 2019

any updates on that?

@RyanCavanaugh
Copy link
Member

Which issue is approved to take a PR (i.e. is in the Backlog milestone) ?

@johnsoncodehk
Copy link
Author

This problem may never be concerned about.
But here is a quick fix:
Search and replace all !currentModuleInfo.exportEquals to false under TYPESCRIPT_DIR/lib/

@RyanCavanaugh
Copy link
Member

We need an approved issue for a PR to be looked at, but there doesn't appear to be one.

Logged #32934 as the typeof check seems reasonable

@bdero
Copy link

bdero commented Sep 17, 2019

I'm using Typescript in an embedded V8 context, and the engine does not assign exports automatically. Instead it only populates module.exports.

In my case, my code is not intended to run in any other JavaScript environment, so as a quick and dirty hack to delete these lines in the meantime, I'm using the tsc-watch tool to fire a script after successful watch builds in order to automatically delete the lines.

package.json scripts:

  "scripts": {
    "watch": "sh node_modules/.bin/tsc-watch --onSuccess 'npm run patchTSOutput'",
    "patchTSOutput": "find . -path ./node_modules -prune -o -print | grep \\.js$ | xargs -n 1 ex '+g/^Object\\.defineProperty(exports,/d' -cwq"
  },

Just thought I'd share for other onlookers in the same situation. If you're running into this problem and you want to target many JavaScript environments, you'd probably be better off inserting undefined guards instead (similar to the suggestion in #32934).

Copy link

@Reality2byte Reality2byte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T

@microsoft microsoft locked as resolved and limited conversation to collaborators Nov 5, 2025
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants