Closed incompletude closed 3 years ago
are you still getting this error
Yes,
node_modules/@ntegral/nestjs-s3/dist/services/s3.service.d.ts:3:40 - error TS2507: Type 'typeof S3' is not a constructor function type.
3 export declare class S3Service extends S3 {
This is my class. If you can help me to solve it, i will save the commit.
import { Injectable, NotFoundException } from "@nestjs/common"
import { InjectS3 } from "@ntegral/nestjs-s3"
import { UserInputError } from "apollo-server-express"
import * as S3 from "aws-sdk/clients/s3"
import { EnvConfig } from "~/common/env.config"
import { FileUploadInput } from "./dto/file-upload.input"
import { FileUploadObject } from "./dto/file-upload.object"
import { FileInput } from "./dto/file.input"
@Injectable()
export class FileService {
public constructor(@InjectS3() private readonly s3: S3) {}
public async upload(fileInput: FileInput, fileUploadInput: FileUploadInput): Promise<FileUploadObject> {
if (!fileInput.mimetype.match(/(jpg|jpeg|png|gif|pdf)$/)) {
throw new UserInputError("Invalid mimetype")
}
const key = `${fileUploadInput.slug}/${Math.floor(Date.now() / 1000)}.${fileInput.mimetype.split("/").slice(-1)[0]}`
const params = { Bucket: EnvConfig.S3_BUCKET, Key: key, Body: fileInput.buffer }
await this.s3.putObject(params).promise()
return {
key,
}
}
public async download(key: string): Promise<string> {
try {
const params = { Bucket: EnvConfig.S3_BUCKET, Key: key, Expires: 5 * 60 }
const url = await this.s3.getSignedUrlPromise("getObject", params)
return url
} catch (error) {
throw new NotFoundException()
}
}
}
I'll look into this.
{ "name": "nestjs-s3", "version": "0.0.1", "description": "", "author": "", "private": true, "license": "UNLICENSED", "scripts": { "prebuild": "rimraf dist", "build": "nest build", "format": "prettier --write \"src//*.ts\" \"test/*/.ts\"", "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}//*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { "@nestjs/common": "^7.0.0", "@nestjs/config": "^0.5.0", "@nestjs/core": "^7.0.0", "@nestjs/platform-express": "^7.0.0", "@ntegral/nestjs-s3": "^1.0.3", "aws-sdk": "^2.766.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^6.5.4" }, "devDependencies": { "@nestjs/cli": "^7.0.0", "@nestjs/schematics": "^7.0.0", "@nestjs/testing": "^7.0.0", "@types/express": "^4.17.3", "@types/jest": "25.1.4", "@types/node": "^13.9.1", "@types/supertest": "^2.0.8", "@typescript-eslint/eslint-plugin": "^2.23.0", "@typescript-eslint/parser": "^2.23.0", "eslint": "^6.8.0", "eslint-config-prettier": "^6.10.0", "eslint-plugin-import": "^2.20.1", "jest": "^25.1.0", "prettier": "^1.19.1", "supertest": "^4.0.2", "ts-jest": "25.2.1", "ts-loader": "^6.2.1", "ts-node": "^8.6.2", "tsconfig-paths": "^3.9.0", "typescript": "^3.7.4" }, "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".spec.ts$", "transform": { "^.+\.(t|j)s$": "ts-jest" }, "coverageDirectory": "../coverage", "testEnvironment": "node" } }
This is the package.json for the sample project I just tested using the library. I did not get the error that you noted above?
Have you tried the one I sent you?
Did you add the configuration for the module to your app.module file??
import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { S3Module } from '@ntegral/nestjs-s3'; import { AppController } from './app.controller'; import { AppService } from './app.service';
@Module({
imports: [
ConfigModule,
S3Module.forRootAsync({
imports: [ConfigModule],
useFactory: async (cfg: ConfigService) => ({
accessKeyId: cfg.get
See the sample app.module file that configures the module
Yes, my module does contain this:
import { Module } from '@nestjs-common';
import { S3Module } from '@ntegral/nestjs-s3';
@Module({
imports: [
S3Module.forRoot({
accessKeyId: 'aws_access_key_id',
secretAccessKey: 'aws_secret_access_key',
region?: 'aws_region_id',
sessionToken?: 'aws_session_token', | null,
apiVersion?: 's3_api_version' //based on s3 api version //
}),
],
})
export class AppModule {}
I've not been able to recreate the error that you are seeing?
Unable to reproduce this issue
Sorry, i just got the time to build a test-app.
npm i
npm run start:dev
Most likely something related to tsconfig.json
.
Can you reopen pls?
@ntegral
Hello, I'm getting an error:
node_modules/@ntegral/nestjs-s3/dist/services/s3.service.d.ts:3:40 - error TS2507: Type 'typeof S3' is not a constructor function type.
3 export declare class S3Service extends S3 {
My package.json:
I this it doesn't support nest 7.