Can't create an instance of SimpleGit in Typescript
See original GitHub issueHi, As I’m trying to get simple-git working with typescript, I try to clone a repository if my baseDir doesn’t exists
If dir exists and trying to fetch and pull, everything’s alright
Here my code :
import { existsSync } from 'fs-extra'
import simplegit from 'simple-git/promise'
export class GitService {
private git: simplegit.SimpleGit
private readonly path: string
private readonly repo: string
constructor () {
this.path = process.env.GIT_PATH
this.repo = process.env.GIT_REPO
if (!existsSync(this.path)) {
simplegit().silent(true).clone(this.repo, this.path).catch()
}
this.git = simplegit(this.path).silent(true)
}
public async getLastVersion () {
await this.git.fetch()
return this.git.pull('origin', 'master')
}
public getPath (): string {
return this.path
}
}
While trying to get instance of simplegit to make my clone, I get this error :
projectPath\node_modules\simple-git\promise.js:58
return Object.keys(git.constructor.prototype).reduce(function (api, fn) {
^
TypeError: Cannot read property 'constructor' of undefined
at Object.module.exports [as default] (projectPath\node_modules\simple-git\promise.js:58:27)
at new GitService (projectPath\src\services\GitService.ts:17:25)
at new Bot (projectPath\src\Bot.ts:30:23)
at Object.<anonymous> (projectPath\src\index.ts:22:13)
at Module._compile (module.js:652:30)
at Module.m._compile (projectPath\node_modules\ts-node\src\index.ts:439:23)
at Module._extensions..js (module.js:663:10)
at Object.require.extensions.(anonymous function) [as .ts] (projectPath\node_modules\ts-node\src\index.ts:442:12)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
Any idea how I can resolve this problem ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (3 by maintainers)
Top Results From Across the Web
How to jest.mock simple-git/promise - Stack Overflow
Here is the unit test example: index.ts : import git from 'simple-git/promise'; function main() ...
Read more >simple-git - npm
Simple Git. NPM version. A lightweight interface for running git commands in any node.js application. Version 3 - Out Now.
Read more >Building a MEAN REST API and host in the Heroku cloud ...
Run the following command to create a new Heroku app: ... Create a new tsconfig.json file which will define the TypeScript project settings....
Read more >Typescript dependency injection: setting up InversifyJS IoC for ...
When executed, the main file is 'new-up-ing' (manually creating a new instance of a class) the service class, calling it's getAllNames ...
Read more >Typescript with Jasmine: easy project setup | by Turhan Oz
In this article, we will go straight to the point for creating a ... "description": "example of typescript project with unit tests ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As this has been added to an issue relating to a different major release of the library, please can you create a new issue and include the version of TypeScript are you using? Thanks
You can import the constructor and types from
simple-git/promise
using:Which works in my current test script based on: