Skip to content

Getting error "TypeScript: emit failed" when using allowJs option in typescript@next #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mohitspawar opened this issue Jan 9, 2016 · 7 comments
Labels

Comments

@mohitspawar
Copy link

I am using typescript@next (Version 1.8.0-dev.20160108) with tsconfig.json as

{
    "compileOnSave": false,
    "filesGlob": [
        "./src/**/*.ts",
        "./src/**/*.js",
        "!./node_modules/**/*.ts",
        "!./node_modules/**/*.js"
    ],
    "compilerOptions": {
        "allowJs": true,
        "target": "es5",
        "module": "amd",
        "outdir": "./output",
        "declaration": false,
        "noImplicitAny": false,
        "noResolve": true,
        "removeComments": true,
        "noLib": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
    }
}

I am trying to use the allowJs option to transpile .js files.
The build task is failing with error "TypeScript: emit failed". There is no other information.
I am not sure how to get more information about the error.

Does gulp-typescript support the allowJS option ? Do I have to do anything different for js files ?

This is my build task:

gulp.task('ts:build', function () {
  var tsResult =  gulp.src(['src/**/*.ts', 'src/**/*.d.ts', 'src/**/*.js'])
    .pipe(print())
    .pipe( sourcemaps.init({ loadMaps: true }))
    .pipe(ts(tsProject));

  return merge([
    tsResult.dts
    .pipe(gulp.dest(paths.output.typings)),

    tsResult.js
    .pipe(sourcemaps.write({ includeContent: true }))
    .pipe(gulp.dest('output'))
  ]); 
});
@ivogabe
Copy link
Owner

ivogabe commented Jan 9, 2016

How did you define tsProject? It should include a reference to your typescript installation, like this:

var tsProject = ts.createProject('tsconfig.json', { typescript: require('typescript') });

@mohitspawar
Copy link
Author

Yes. That is how I have defined tsProject.

var tsProject = ts.createProject('./tsconfig.json', {
  typescript:  require('typescript'),
  noExternalResolve: true
});

@stephenlautier
Copy link

I'm also getting this issue and im not using allowJs and im using typescript 1.8.0. For some reason errors are not emitted

This is what I have

// tsconfig

{
    "compilerOptions": {
        "module": "amd",
        "target": "es5",
        "noImplicitAny": true,
        "noEmit": true,
        "noLib": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "declaration": false
    },
    "exclude": [
        "node_modules",
        "dist",
        "_artifact"
    ]
}

// gulp

function getTscOptions() {
    var typescript = require("typescript");
    return $.typescript.createProject("tsconfig.json", {
        sortOutput: true,
        typescript: typescript
    });
}

gulp.task("compile:ts", () => {

    const tsProject = getTscOptions();
    const tsResult = gulp.src([config.src.tsd, config.src.ts, `!${config.test.files}`])
        .pipe($.plumber())
        .pipe($.sourcemaps.init())
        .pipe($.typescript(tsProject));

    return $.merge2([
        tsResult.js
            .pipe($.ngAnnotate())
            .pipe($.sourcemaps.write("."))
            .pipe(gulp.dest(`${config.artifact}/amd`))
    ]);
});

@stephenlautier
Copy link

Sorry from my end seems to be working now, I simply changed "noEmit": false

@ivogabe
Copy link
Owner

ivogabe commented Feb 3, 2016

Are you using the latest version of gulp-typescript?

@ivogabe
Copy link
Owner

ivogabe commented Feb 3, 2016

@stephenlautier Ow wait, I think you're mistaking noEmit with noEmitOnError. The latter prevents emit when there is a build error, whereas noEmit just never emits a file.

@stephenlautier
Copy link

Should be, I'm using v2.10.0 of gulp-typescript. but as I said by simply changing the "noEmit": false (before it was true) its working fine.
Simply the behaviour changed from the previous version for anyone who have the same issue which I had (might be from TSC itself).

@ivogabe Correct, I'm not mistaking it however, i just had that one set previously and it used to work still on typescript 1.7.x, now it doesn't which I believe its the correct way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants