te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Angular Cannot Find Name Buffer - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular Cannot Find Name Buffer - Stack Overflow

programmeradmin3浏览0评论

I keep getting this error when trying to use Jimp to execute the code bellow. I read around the issues and found that there were issues with buffer in version .28. I downgraded to .27 and this didn't help. I was wondering if this was still an issue or if I incorrectly imported the files.

ERROR in node_modules/jimp/jimp.d.ts(18,24): error TS2304: Cannot find name 'Buffer'.

I think this may be an error with the .d.ts file because I'm not using buffer in the code.

I have imported the type for Jimp into my dev dependencies (npm i --save-dev @types/node), but the new version of Jimp says it doesnt need these types it has its own. I have also put "types":["node"] into my tsconfig.json file.

Code

import { Component, OnInit } from '@angular/core';
import * as jimp from 'jimp';

@Component({
  selector: 'app-jimp-test',
  templateUrl: './jimp-testponent.html',
  styleUrls: ['./jimp-testponent.css']
})
export class JimpTestComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    this.testJimp();
  }

  testJimp() {
    jimp.read('assets/testInput.jpg').then( (img) => {
      img.clone().blur(1).write('assets/testOutput.jpg');
    });
  }

}

Dependencies

{
  "name": "my-playground",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/mon": "^6.0.3",
    "@angular/piler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "core-js": "^2.5.4",
    "jimp": "^0.2.28",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "~6.0.8",
    "@angular/piler-cli": "^6.0.3",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/jimp": "^0.2.28",
    "@types/node": "^8.9.5",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

Angular Versions

@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3

Jimp Version

0.2.28

tsconfig.json

{
  "pileOnSave": false,
  "pilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "pilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

I keep getting this error when trying to use Jimp to execute the code bellow. I read around the issues and found that there were issues with buffer in version .28. I downgraded to .27 and this didn't help. I was wondering if this was still an issue or if I incorrectly imported the files.

ERROR in node_modules/jimp/jimp.d.ts(18,24): error TS2304: Cannot find name 'Buffer'.

I think this may be an error with the .d.ts file because I'm not using buffer in the code.

I have imported the type for Jimp into my dev dependencies (npm i --save-dev @types/node), but the new version of Jimp says it doesnt need these types it has its own. I have also put "types":["node"] into my tsconfig.json file.

Code

import { Component, OnInit } from '@angular/core';
import * as jimp from 'jimp';

@Component({
  selector: 'app-jimp-test',
  templateUrl: './jimp-test.ponent.html',
  styleUrls: ['./jimp-test.ponent.css']
})
export class JimpTestComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    this.testJimp();
  }

  testJimp() {
    jimp.read('assets/testInput.jpg').then( (img) => {
      img.clone().blur(1).write('assets/testOutput.jpg');
    });
  }

}

Dependencies

{
  "name": "my-playground",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/mon": "^6.0.3",
    "@angular/piler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "core-js": "^2.5.4",
    "jimp": "^0.2.28",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "~6.0.8",
    "@angular/piler-cli": "^6.0.3",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/jimp": "^0.2.28",
    "@types/node": "^8.9.5",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

Angular Versions

@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3

Jimp Version

0.2.28

tsconfig.json

{
  "pileOnSave": false,
  "pilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "pilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}
Share Improve this question edited Jul 10, 2018 at 19:44 Jonathan asked Jul 10, 2018 at 2:31 JonathanJonathan 231 gold badge1 silver badge6 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

You can try this:

This line should be on top:

declare const Buffer

and it should pile without errors.

With new version of Typescript, you can also use official declaration files:

npm i -g typescript@next
npm i --save-dev @types/node

and add "types" : ["node"] in tsconfig.app.json file.

Don't know if can help anybody but I solved it by adding:

import {Utils} from 'tslint'

into my ponent. Crazy it worked

Please add "types" : ["node"] in tsconfig.app.json

发布评论

评论列表(0)

  1. 暂无评论