簡體   English   中英

Node.js:錯誤“導出的外部程序包鍵入文件”

[英]Node.js: Error “Exported external package typings file”

簡而言之:

  • Node.js項目,從javascript變為打字稿
  • npm安裝貓鼬
  • 鍵入安裝貓鼬-保存-環境

如果我做“ import mongoose = require(“ mongoose”);” 然后輸入execute 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中,如果我將鼠標懸停,則消息是相同的,但是另一方面,它使用類型定義,因為我可以正常解析我的貓鼬模塊。 我不明白為什么它認為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/**" ] 

不是模塊。

只需運行以下快速測試,它就可以正常工作。 請確保您使用的是最新的typings / typescript

更新輸入

npm i typings -g

我測試過的證明🌹

在此處輸入圖片說明

我不太確定問題出在哪里,但是最后刪除node_modules和npm install解決了問題。 也許我在實驗時銷毀了node_modules中的一些文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM