Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Fatal error: Cannot call method 'accept' of undefined #12

Open
scriby opened this issue Jul 2, 2014 · 6 comments
Open

Fatal error: Cannot call method 'accept' of undefined #12

scriby opened this issue Jul 2, 2014 · 6 comments

Comments

@scriby
Copy link

scriby commented Jul 2, 2014

I have a grunt task setup like so:

grunt.registerTask('pre-commit', [
    'typescript:build',
    'tslint',
  ]);

When it runs tslint as part of that task, it always throws the "Cannot call method 'accept' of undefined" error while running. However, I can run just the tslint task by itself without issue. If I comment out the typescript build step, it also works correctly.

The error does not include a stack trace or any more details. Running with --debug doesn't produce any more useful output. Running with --verbose shows it reading some files, then the error message appears and it crashes.

Here are my task definitions:

    tslint: {
      options: {
        configuration: grunt.file.readJSON('tslint.json')
      },
      build: {
        files: {
          src: [ 'app/**/*.ts' ]
        }
      }
    },

    typescript: {
      build: {
        src: [ 'app/**/*.ts' ],
        options: {
          module: 'amd',
          noImplicitAny: true,
          sourceMap: true,
          target: 'es5'
        }
      },

      watch: {
        src: [ 'app/**/*.ts' ],
        options: {
          module: 'amd',
          noImplicitAny: true,
          sourceMap: true,
          target: 'es5',
          watch: 'app'
        }
      }
    },

Do you have any idea what could be causing this or how I can get more information about the source of the failure?

Thanks,

Chris

@MathiasGronseth
Copy link

Experiencing the exact same problem.

I found that the following work fine:
grunt tslint typescript
but this fail:
grunt typescript tslint

So there error seem to have something to do with the ordering.

@MathiasGronseth
Copy link

This SEEM to be caused by both visual studio AND the Typescript task building the same files.

@scriby
Copy link
Author

scriby commented Jul 10, 2014

I'm not running Visual Studio, but we do build our typescript via a grunt task that watches for changes. The error seems to occur whether the watcher is running or not.

@philipbulley
Copy link

Similar problem here when attempting to lint after typescript compilation. Using grunt-tslint 2.3.1-beta and tslint 2.3.1-beta.

This fails:

$ grunt typescript tslint

Running "typescript:base" (typescript) task
File build/script/main.js created.
js: 1 file, map: 1 file, declaration: 0 files (2272ms)

Running "tslint:files" (tslint) task
Warning: undefined is not a function Use --force to continue.

Aborted due to warnings.

This works but is the wrong way around (I'd rather be linting after successful compilation):

$ grunt tslint typescript

Running "tslint:files" (tslint) task
>> 130 files lint free.

Running "typescript:base" (typescript) task
File build/script/main.js created.
js: 1 file, map: 1 file, declaration: 0 files (2242ms)

Done, without errors.

@adidahiya
Copy link
Contributor

@milkisevil can you please post your gruntfile?

@philipbulley
Copy link

Sure @adidahiya , I've reduced down to the relevant parts and re-tested. This continues to have same behaviour as described previously.

module.exports = function (grunt) {

    var typescriptPaths = [
      'src/script/base/pattern/Event.ts',
      // ... 128 files omitted for berevity ...
      'src/script/MainContext.ts'
    ];

  grunt.initConfig({
      pkg: grunt.file.readJSON('package.json'),

      typescript: {
        base: {
          src: typescriptPaths,
          dest: 'build/script/main.js',
          options: {
            target: 'es5',
            sourceMap: true
          }
        }
      },

      tslint: {
        options: {
          configuration: grunt.file.readJSON("tslint.json")
        },
        files: {
          src: typescriptPaths
        }
      }

    }
  );

  grunt.loadNpmTasks('grunt-typescript');
  grunt.loadNpmTasks('grunt-tslint');

  // BUG: `tslint` should ideally be run AFTER `typescript` but: https://github.com/palantir/grunt-tslint/issues/12
  grunt.registerTask('scriptNotWorking', ['typescript', 'tslint']);
  grunt.registerTask('scriptWorkingButNotIdeal', ['tslint', 'typescript']);
}

Thanks!

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

No branches or pull requests

4 participants