【问题标题】:Node.js: Error "Exported external package typings file"Node.js:错误“导出的外部包类型文件”
【发布时间】:2016-04-07 05:33:24
【问题描述】:

简而言之:

  • Node.js 项目,从 javascript 更改为 typescript
  • npm install mongoose
  • typings install mongoose --save --ambient

如果我这样做'import mongoose = require("mongoose");'并输入执行 gulp 我得到:

server/categories/categories.model.ts(1,29): error TS2656: 
Exported external package typings file
'/vagrant/node_modules/mongoose/index.ts' is not a module.
Please contact the package author to update the package definition.

在 Visual Studio Code 中,如果我悬停,消息是相同的,但另一方面它使用类型定义,因为我可以正常解析我的 mongoose-Module。我不明白为什么它认为 index.ts 应该是类型定义。

我不太确定这些信息是否足够,如果没有,请告诉我。

提前致谢。

摘录:

  • gulpfile.js

    var tsProject = tsc.createProject("tsconfig.json");
    
    gulp.task("build", function() {
    return gulp.src([
            "server/**/**.ts",
            "typings/main.d.ts"            
        ])
        .pipe(tsc(tsProject))
        .js.pipe(gulp.dest("server/"));
    });
    
  • tsconfig.json

         "compilerOptions": {
    "target": "es5",
    "sourceMap": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "isolatedModules": false,
    "jsx": "react",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "preserveConstEnums": true,
    "suppressImplicitAnyIndexErrors": true
    },
     "filesGlob": [
     "**/*.ts",
     "**/*.tsx",
     "!node_modules/**",
     "!typings/browser/**"
     ]
    

【问题讨论】:

    标签: node.js module typescript gulp


    【解决方案1】:

    不是一个模块。

    刚刚运行了以下快速测试,它运行良好。确保您使用的是最新的 typings / typescript

    更新类型

    npm i typings -g

    我测试过的证明?

    【讨论】:

    • 感谢您的回答,我认为这不是问题(打字是新安装的 0.7.12 版本)。
    • 我做了: mkdir mongotest cd mongotest node int (默认) npm install node mongoose --save typings install node mongoose --save --ambient 从上面获取 tsconfig.json 和你的 test.ts tsc -p ./tsconfig.json,我得到以下信息(以及更多类似的错误):typings/main/ambient/mocha/index.d.ts(25,5): error TS2300: Duplicate identifier 'bail'我看到使用了类型/主/环境和类型/浏览器/环境,我认为“filesGlob”在这里应该有帮助......
    • 但是我在这里看不到原来的错误,所以我的问题是: - 为什么 filesGlob 不能按预期工作 - 另一个可能导致 mongoose 中的 index.ts 的想法被识别为模块? (正如在这个小测试中没有看到的那样)
    【解决方案2】:

    我不太确定问题出在哪里,但最终删除 node_modules 和 npm install 解决了问题。也许我在试验时破坏了 node_modules 中的一些文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多