找不到' ramda'的类型定义文件

时间:2018-02-21 11:31:09

标签: angular cordova typescript ionic-framework ramda.js

我有一个项目Ionic 2& Angular 2。

我在我的代码中使用RamdaJS,这完全适用于这些命令:

  • ionic serve
  • ionic cordova build android
  • ionic cordova run android

但是当我尝试执行此命令:ionic cordova build android --prod --release时,我收到有关Ramda和Type的错误。

查看我package.json的一部分:

"dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/flex-layout": "^2.0.0-rc.1",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/material": "2.0.0-beta.2",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@angular/router": "3.4.8",
    "@ionic-native/camera": "3.7.0",
    "@ionic-native/core": "3.7.0",
    "@ionic-native/network": "3.7.0",
    "@ionic-native/splash-screen": "3.7.0",
    "@ionic-native/status-bar": "3.7.0",
    "@ionic/storage": "2.0.0",
    "cordova-plugin-device": "^2.0.1",
    "cordova-plugin-ionic-keyboard": "^2.0.5",
    "cordova-plugin-ionic-webview": "^1.1.16",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "hammerjs": "2.0.8",
    "ionic-angular": "2.3.0",
    "ionicons": "3.0.0",
    "material-design-icons": "3.0.1",
    "moment": "2.18.1",
    "moment-duration-format": "1.3.0",
    "ng2-translate": "5.0.0",
    "ng2-webstorage": "1.5.1",
    "ngx-pipes": "1.5.7",
    "ramda": "0.23.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.7.2",
    "cordova-android": "~7.0.0"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.2.2",
    "@types/ramda": "github:types/npm-ramda",
    "@types/moment-duration-format": "1.3.1",
    "typescript": "2.2.1"
  }

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths" : {
       "ramda": [
         "location-of-types/npm-ramda-package/index"
       ]
     },
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

尝试为生产构建时出错:

[12:26:31]  typescript error
            Cannot find type definition file for 'ramda'.

Error: Failed to transpile TypeScript

2 个答案:

答案 0 :(得分:3)

按照DefinitlyTyped的推荐,通过@types/packageName安装类型。

对于NPM,请执行:

npm install @types/ramda --save-dev

对于YARN使用:

yarn add @types/ramda --dev
默认情况下, Typescript会在@types内查找名为node_modules的directiory,以查找类型定义:

  

默认情况下,所有可见的“@types”包都包含在您的编译中。任何封闭文件夹的node_modules / @类型中的包被视为可见;具体而言,这意味着包装在./node_modules/@types/,../node_modules/@types/,../../node_modules/@types/等。

     

如果指定了typeRoots,则只包含typeRoots下的包。

tsconfig.json docs

答案 1 :(得分:1)

按照此处的安装说明操作:https://github.com/types/npm-ramda

# using npm
npm install --save-dev types/npm-ramda#dist
     

如果不使用npm / yarn,您可能需要将这些类型添加到路径中   tsconfig.json:

     

完整套餐:

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths" : {
       "ramda": [
         "location-of-types/npm-ramda-package/index"
       ]
     }
  }
}