I have a problem when I try to start my angular 6 project. I've got this error :
"TSError: тип Unable to compile TypeScript: git.version.ts(34,29): error TS2339: Property 'combineLatest' does not exist on type 'typeof Observable'."
It worked well with Angular 5 but I updated RxJs (from 5 to 6) and now it doesn't work.
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { Observable, combineLatest } from 'rxjs';
let exec = require('child_process').exec;
let tag = new Observable<string>(s => {
exec('git describe --tags $(git rev-list --tags --max-count=1)',
function (error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});
let revision = new Observable<string>(s => {
exec('git rev-parse --short HEAD',
function (error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});
Observable.combineLatest(tag, revision).subscribe(([tag, revision]) => {
console.log(`version: '${tag}', revision: '${revision}'`);
const content = '// this file is automatically generated\n' +
`export const version = {version: '${tag}', revision: '${revision}'};`;
writeFileSync(
'src/environments/version.ts',
content,
{encoding: 'utf8'}
);
});
The command I launch : "ts-node git.version.ts" is to get the commit and the tag version I work with.
Thank you very much !
UPDATE :
combineLatest(tag, revision).subscribe(([tag, revision]) => {
console.log(`version: '${tag}', revision: '${revision}'`);
const content = '// this file is automatically generated\n' +
`export const version = {version: '${tag}', revision: '${revision}'};`;
writeFileSync(
'src/environments/version.ts',
content,
{encoding: 'utf8'}
);
});
I haven't any error about CombineLatest but I have an error from ts-node :
function (exports, require, module, __filename, __dirname) { import { writeFileSync } from 'fs';
^^^^^^
SyntaxError: Unexpected token import
Any idea ?
UPDATE 2 : To fix this error :
"config": "ts-node -O '{\"module\": \"commonjs\"}' git.version.ts",
In package.json