Repository navigation
Typescript ESM issue聽#48835
Description
Activity
andrewbranch commented
on Apr 25, 2022 MemberMore actionsThis is happening because
moduleResolutionis set tonode. NormallymoduleResolutionwould not effect the module emit, but module resolution is kind of tied up in deciding whether a given file is a CJS or ESM module. Wesley Wigham (@weswigham) is this expected? I would have thought we would get theimpliedNodeFormatjust withmodule.Reacted by Jared Rethmanandrewbranch commented
on Apr 25, 2022 MemberMore actions(That said, Andy Wilson (@The-Code-Monkey), you should unset
moduleResolutionso it defaults to the right thing.)Wesley Wigham (@weswigham) is this a bug?
I mean, technically it's working as intended -
moduleResolutionatnodeessentially forbids us from reading modern package metadata from package files/extensions, so that data isn't available for emit to base its' decisions on, which, in turn, means everything compiles as modern-node-cjs, which still might be what you want, since that's the only emit target that is commonjs, but doesn't transform dynamicimport.- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on May 24, 2022 So I'm facing a problem when I set
moduleResolutiontonodethen I will face this problem, but setting it tonode16then I will face: #49160. So basicallynode16is unusable for me.Reacted by Tam谩s Heged疟stypescript-bot commented
on May 27, 2022 ContributorMore actionsThis issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
- locked as resolved and limited conversation to collaborators
on Oct 22, 2025
Bug Report
馃攷 Search Terms
ESM build error
馃晽 Version & Regression Information
Its in the nightly @next build do to with building an ESM package.
馃捇 Code
Hey guys, i need help i have a package im trying to convert to esm i have updated the package.json to type: module and the stuff in tsconfig.
https://github.com/The-Code-Monkey/TechStack/tree/feature/tcm-cli-to-esm/packages/tcm-cli
This is the package location, I am confused as it builds but when i try and use the dist index.js to lint the package it throws an error saying
Object.defineProperty(exports, "__esModule", { value: true });
^
ReferenceError: exports is not defined in ES module scope
This is because that line is being added by typescript to the index.js file within dist, there arent any other uses of the word exports in the dist folder so im not sure why typescript is adding it.
馃檨 Actual behavior
It adds the
Object.defineProperty(exports, "__esModule", { value: true });line into each of my files馃檪 Expected behavior
This line shouldn't be added as im targeting ES2020 and nodenext with type: module.
which means it should compile down to esm but tsc is still compiling down to cjs for some reason.