ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
839 stars 129 forks source link

UnhandledPromiseRejectionWarning: Error: TypeScript: Compilation failed #640

Open wuhaiyang opened 4 years ago

wuhaiyang commented 4 years ago

error description:

....
TypeScript: 76 semantic errors
TypeScript: emit succeeded (with errors)
(node:17577) UnhandledPromiseRejectionWarning: Error: TypeScript: Compilation failed
    at Output.mightFinish (/.../node_modules/_gulp-typescript@5.0.1@gulp-typescript/release/output.js:130:43)
    at applySourceMap.then.appliedSourceMap (/..../node_modules/_gulp-typescript@5.0.1@gulp-typescript/release/output.js:65:22)
(node:17577) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17577) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

build.js

const tsProject = ts.createProject(path.join(__dirname, '../tsconfig.json'), {
  getCustomTransformers: () => ({
    before: [
      kobexClassTransformer(),
      kobexMethodsTransformer(),
    ],
  }),
})

task('ts', (done) => {
  const res = src([tsFileGlob])
    .pipe(tsProject())
    .pipe(through.obj((chunk, encoding, cb) => {
      const transformedFile = chunk.clone()

      transformedFile.contents = Buffer.concat([Buffer.from('/* istanbul ignore file */\n'), chunk.contents])

      cb(null, isProd ? chunk : transformedFile)
    }))
    .pipe(dest(targetPath))
    .once("error", function () {
      this.once("finish", () => process.exit(1));
    })
  done()
  return res
})

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "types": ["mini-types", "./@types"],
    "declaration": true,
    "plugins": [
      { "transform": "@ali/ts-transform-kobex/lib/class-transformer" },
      { "transform": "@ali/ts-transform-kobex/lib/methods-transformer" }
    ],
    "lib": ["es5", "es2015.promise", "es2015.collection", "es2015.iterable", "dom"]
  },
  "include": ["src/**/*.ts"],
}
wuhaiyang commented 4 years ago

remove this code block , There is still a compilation error .once("error", function () { this.once("finish", () => process.exit(1)); })

wuhaiyang commented 4 years ago

"gulp": "^4.0.2", "gulp-typescript": "^5.0.1",

SunshineH2 commented 3 years ago

resolved?

SunshineH2 commented 3 years ago

I have the same problem, help!

witszc commented 1 year ago

I have the same problem, how can I solve it?

witszc commented 1 year ago

@wuhaiyang Have you solved it yet?