microsoft / microsoft/TypeScript

Code generated by Webpack shows error in `exports` parameters in module lambdas as if they were a conflicting global `exports`

Open
#59,420 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

webpack Cannot redeclare exported variable __esModule ts2323 ts 2323 ts(2323)

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs
⏯ Playground Link

https://www.typescriptlang.org/play/?strict=false&noImplicitAny=false&strictPropertyInitialization=false&strictBindCallApply=false&alwaysStrict=false&esModuleInterop=false&declaration=false&target=99&jsx=0&module=0&noFallthroughCasesInSwitch=true&ts=5.5.3&filetype=js#code/PQKj+ACAKaEpIF4B8kDelhQO4FMBGADgIYDGA1gEID21ALgM50BOxhAUKOGFAJABuxZpAD6IvETLkRAW2oATAK4AbXAzFIYAbU4hIABkghgunjGhjFAO0UNc88QRIVZClbgA0kXAA9C1ZkYvMQlnaWZcAEdFAEsIsQQUdHZ2ACJbXEgmZhjSOlSAbhSAeXwAK1w8gDp5XAAzGKtcAAVmakJcQIBPaF9-QIYvVLE1AFk3VVSvaAxBZUVcAC5IFgXIAF84OCKsSC1SBUzqOsg5JVUDAF0UrmMNuA9dSABGIxNbqFhLGzsHUKlXOdPN4-AFGIlUGgUuk7FkWLl8kV2KUKtVag0mq12p06D0+mDBpBhiIxhNcFMYLNiPMlitmGtNttOFB9odIMdTmSXl5cHRSFUBdcbhB7o9biLeJcmeLuLK5fKFYqlcqFe85XxdgAVAAWmTO7kgpDIutM3D4gmEIScAP1qhERtIuo0iHQ6x26sgvFNEq1usgEWicUydWseRi1Cs3rMvBDVjDEdEjkkLgDsXiImgttwAEl5AgoTK7rxeLsAMK6iiQGInLNVhhVqyG424KNFgRCJuO+zjIGaK3J6RZ+3NsRaLO5y7u2V8XjVmAO3XyHsGgCEiBd1nRjXs+dbM94EToimYjYX3bJVXxAynZs9vHWe7vZYixDomWIkCa2E5vegxCs8iQIQih0FWoGNHQ1ArH6Z5wI+xYWj+Bouv2YSAu4w5dqO47yJcmgFh6xYllAVhQVmVQxIBTT2PY8HFrspFIaoVTKNQxC1FRuA0fIdG8FejDLGgD6FjObrwXRuwAKI+JUIGZHQfq1rG8aRiJd6oTaZLqCIY5khOmZkl45H8YSGkplEaa4AkN4ShJUAAEq8sejYKZkJnsicrlMS2anFoezneZeoLXvBwmEa2KqRVF0Uqmq06evBuxMEIR4cL5uwADJsYBuBWCwXTeZA-6Af5J4gv0jCJVAOoxPWuX5YVtX+vUnS5aQ9iQPgBX0LqwhZvWDBQTEoFGlYADkoH4JkjTKNuPG+YhZnSCZzqJv85mBum0D6NKhGLUmaH8SIdBCAA5ryq0mTZ0Z1AE0CITEDZrdaLgrSICBLSSwV0MdZ0XTpMR4ShB0Am9WiA9dRbVhYIOvd92lVCMDDLqoCAopUdA1PU25Yh03Qw+ty3fb9zDnT9IhDEjKPkl4VI0ssqyZJskN8I+mzwOwRRAA

💻 Code
/******/ (() => { // webpackBootstrap
/******/ 	var __webpack_modules__ = ([
/* 0 */
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
// [code of module 0]

/***/ }),
/* 1 */
/***/ ((__unused_webpack_module, exports) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
// [code of module 1, etc...]


/***/ }),
/******/ 	]);
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module is referenced by other modules so it can't be inlined
/******/ 	var __webpack_exports__ = __webpack_require__(0);
/******/ 	var __webpack_export_target__ = exports;
/******/ 	for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
/******/ 	if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
/******/ 	
/******/ })()
;

🙁 Actual behavior

Error TS2323 on every line below:

Cannot redeclare exported variable '__esModule'.

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

It's ignoring the fact exports is a lambda parameter, which should not make it conflict with the ones in other lambdas as if it's the same global exports object. It's like it's treating it as a keyword?
In fact, if you were to rename all those parameters to something else is has no errors (at least in VSCode, TS v5.5.3).

🙂 Expected behavior

No errors should be shown.
Lambda parameter named exports should be treated as just a parameter, not special.
Or at least should be scoped so it doesn't conflict with the other lambdas (which are the way webpack packs modules).

Additional information about the issue

In case it's relevant, here's part of the webpack.config.js.
Use case is bundling a VSCode extension (with multiple modules) for the Web, then inspecting the generated code.

/** @type import('webpack').Configuration */ module.exports = {
  mode: 'none',
  target: 'webworker',
  output: {
    //...
    libraryTarget: 'commonjs',
  },
  resolve: {
    mainFields: ['browser', 'module', 'main'],
    extensions: ['.ts', '.js'],
    //...
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        exclude: /\bnode_modules\b/,
        use: [
          {
            loader: 'ts-loader',
            //...
          }
        ]
      }
    ]
  },
  externals: {
    vscode: 'commonjs vscode',
  },
  performance: {
    hints: false,
  },
  devtool: 'nosources-source-map',
  //...
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground reproduction and the generated module-lambda code; webpack.config.js provides the bundling context. Compare diagnostics for the original exports parameters with the renamed-parameter variant, then trace how lambda scope is handled. Done means the original snippet no longer reports TS2323 while genuine redeclarations remain diagnosed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, webpack
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.