microsoft / microsoft/TypeScript
Code generated by Webpack shows error in `exports` parameters in module lambdas as if they were a conflicting global `exports`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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
💻 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',
//...
};
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der verknüpften TypeScript-Playground-Reproduktion und dem generierten module-lambda-Code; webpack.config.js stellt den Bundling-Kontext bereit. Vergleichen Sie die Diagnosen für die ursprünglichen exports-Parameter mit der Variante mit umbenanntem Parameter und verfolgen Sie anschließend, wie der Lambda-Scope behandelt wird. Die Aufgabe ist abgeschlossen, wenn das ursprüngliche Snippet nicht mehr TS2323 meldet, während echte Neudeklarationen weiterhin diagnostiziert werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript, webpack
- Bereich
- compilers, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100