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
3 Answers
Reset to default 10You 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