【问题标题】:how to trace webpack module resolution?如何跟踪 webpack 模块分辨率?
【发布时间】:2021-09-30 15:17:36
【问题描述】:

我在项目中有 2 个 tslib 版本

| +-- @typescript-eslint/eslint-plugin@3.10.1
| | `-- tsutils@3.21.0
| |   `-- tslib@1.14.1
| `-- eslint@6.8.0
|   `-- inquirer@7.3.3
|     `-- rxjs@6.6.7
|       `-- tslib@1.14.1  deduped
`-- enzyme@3.9.0
  `-- cheerio@1.0.0-rc.10
    `-- tslib@2.3.0

webpack 将 Cheerio 的使用解析为错误的 tslib 1.14 版本,导致运行时错误 tslib_1.__spreadArray is not a function at

/***/ "./node_modules/cheerio/lib/static.js":
/*!********************************************!*\
  !*** ./node_modules/cheerio/lib/static.js ***!
  \********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.merge = exports.contains = exports.root = exports.parseHTML = exports.text = exports.xml = exports.html = void 0;
var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.js");

我能以某种方式追踪 webpack 模块的分辨率吗? 会因为 resolve.modules 而发生吗?

resolve: {
        unsafeCache: true,
        aliasFields: ["browser"],
        mainFields: ["module", "jsnext:main", "browser", "main"],
        modules: [
            "./node_modules",
            path.resolve(context),
            path.resolve(context, "node_modules"),
        ],

【问题讨论】:

  • 你最后解决了吗?提前谢谢你和问候

标签: javascript typescript webpack


【解决方案1】:

删除 webpack resolve.modules "./node_modules" 有帮助

由于自定义的 webpack 解析配置,它确实很有趣

一些内部模块正在调用 require("foo") 并且 "foo" 是从 node_modules 的根目录中获取的,当适当版本的 foo 位于 depper 时

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 2016-04-18
    • 2017-10-06
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2017-03-11
    相关资源
    最近更新 更多