【问题标题】:Variable 'module' must be of type 'any', but here has type 'NodeModule'变量“module”必须是“any”类型,但这里有“NodeModule”类型
【发布时间】:2017-08-17 17:22:00
【问题描述】:

我正在开发一个Angular 项目,最近安装了ng2-dropdown-treeview 1.0.5。安装后,我用npm start重新启动了我的服务器。

我的服务器日志正在打印以下错误:

[PATH]\node_modules\@types\node\index.d.ts:82:13
Subsequent variable declarations must have the same type. Variable 'module' must be of type 'any', but here has type 'NodeModule'.

根据错误,我导航到 index.d.ts:82 并将 declare var module: NodeModule; 更改为 declare var module: any

但这导致我的 devtools 控制台出现错误:

Uncaught TypeError: ctorParameters.map is not a function.

它指向 vendor.bundle.js.35429:

// API of tsickle for lowering decorators to properties on the class.
if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__facade_lang__["e" /* isPresent */])(typeOrFunc.ctorParameters)) {
    var ctorParameters = typeOrFunc.ctorParameters;
    var paramTypes_1 = ctorParameters.map(function (ctorParam /** TODO #9100 */) { return ctorParam && ctorParam.type; });
    var paramAnnotations_1 = ctorParameters.map(function (ctorParam /** TODO #9100 */) {
        return ctorParam && convertTsickleDecoratorIntoMetadata(ctorParam.decorators);
    });
    return this._zipTypesAndAnnotations(paramTypes_1, paramAnnotations_1);

我已经反对像这样更改打包代码,所以我想我会问其他人是否有类似的问题。非常感谢任何帮助!

【问题讨论】:

  • 看起来您的.d.tss 之一中可能有重复的变量 def。你包括了什么类型的defs?你能把问题减少到使用最少数量的模块吗?
  • @SandyGifford,感谢您的参与。我在 custom-types.d.ts 中有 declare module '*';,这是我认为可能存在冲突的唯一地方。但是既然是通配符,应该不会冲突吧?即便如此,为了安全起见,我还是将其更改为declare var module: any;,但它仍然给我同样的问题:(
  • 这可能会导致问题。您可以尝试仅使用这两个 def 和足够的代码来在新项目中重新创建问题吗?
  • 所以,原来问题与ng2-dnd的冲突有关。一旦我删除了对 ng2-dnd 的所有引用,并更改了declare var module: any,问题就解决了。
  • 有意思,可能是.d.ts的问题?

标签: angular typescript npm npm-install


【解决方案1】:

最后,问题是与 ng2-dnd 的依赖冲突。从应用程序中删除其引用后,错误就解决了。

【讨论】:

    【解决方案2】:

    我发生了类似的事情,而不是“任何”,而是“字符串”。不知何故,我不小心添加了导致问题的额外导入。

    import { element } from 'protractor';
    

    这是我的冒犯者。如果其他人遇到此问题,可能会开始提取您的一些导入,直到您弄清楚是您添加的哪个导致这种情况发生。

    【讨论】:

      猜你喜欢
      • 2020-09-11
      • 2016-04-11
      • 2017-10-23
      • 1970-01-01
      • 2020-02-19
      • 2023-01-17
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多