Ncc: Builtin TypeScript bug

Created on 20 Jun 2019  路  5Comments  路  Source: vercel/ncc

The following stack trace is given when using the built-in TypeScript version:

TypeError: Cannot read property 'getOptionsDiagnostics' of undefined
    at Object.getCompilerOptionsDiagnostics (/home/guybedford/Projects/ncc/dist/ncc/loaders/ts-loader.js:153789:28)
    at provideCompilerOptionDiagnosticErrorsToWebpack (/home/guybedford/Projects/ncc/dist/ncc/loaders/ts-loader.js:25004:31)
    at /home/guybedford/Projects/ncc/dist/ncc/loaders/ts-loader.js:24982:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/guybedford/Projects/ncc/dist/ncc/index.js:19628:10), <anonymous>:16:1)
    at AsyncSeriesHook.lazyCompileHook (/home/guybedford/Projects/ncc/dist/ncc/index.js:121606:20)
    at compilation.seal.err (/home/guybedford/Projects/ncc/dist/ncc/index.js:54813:32)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/guybedford/Projects/ncc/dist/ncc/index.js:19628:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/guybedford/Projects/ncc/dist/ncc/index.js:121606:20)
    at hooks.optimizeAssets.callAsync.err (/home/guybedford/Projects/ncc/dist/ncc/index.js:56201:36)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/guybedford/Projects/ncc/dist/ncc/index.js:19628:10), <anonymous>:6:1)
(node:8596) UnhandledPromiseRejectionWarning: Error: Callback was already called.
    at throwError (/home/guybedford/Projects/ncc/dist/ncc/index.js:35007:11)
    at /home/guybedford/Projects/ncc/dist/ncc/index.js:37809:7
    at cache.get (/home/guybedford/Projects/ncc/dist/ncc/index.js:57356:16)
    at needCalls (/home/guybedford/Projects/ncc/dist/ncc/index.js:91498:6)
    at err (/home/guybedford/Projects/ncc/dist/ncc/index.js:91457:11)
    at gotHandlers.push (/home/guybedford/Projects/ncc/dist/ncc/index.js:112872:8)
    at hooks.get.callAsync (/home/guybedford/Projects/ncc/dist/ncc/index.js:91501:6)
    at _promise1.then._result1 (eval at create (/home/guybedford/Projects/ncc/dist/ncc/index.js:19628:10), <anonymous>:30:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Where the underlying bug is this ts-loader call path - https://github.com/TypeStrong/ts-loader/blob/69dc5e2acfff9fad2664c8ec2ea341c794cd157e/src/after-compile.ts#L92 matching the program === undefined path and then calling into TypeScript at the following lines:

        function getSuggestionDiagnostics(fileName) {
            synchronizeHostData();
            return ts.computeSuggestionDiagnostics(getValidSourceFile(fileName), program, cancellationToken);
        }
        function getCompilerOptionsDiagnostics() {
            synchronizeHostData();
            return program.getOptionsDiagnostics(cancellationToken).concat(program.getGlobalDiagnostics(cancellationToken));
        }
        function getCompletionsAtPosition(fileName, position, options) {
            if (options === void 0) { options = ts.emptyOptions; }
            // Convert from deprecated options names to new names
            var fullPreferences = __assign({}, ts.identity(options), { includeCompletionsForModuleExports: options.includeCompletionsForModuleExports || options.includeExternalModuleExports, includeCompletionsWithInsertText: options.includeCompletionsWithInsertText || options.includeInsertTextCompletions });
            synchronizeHostData();
            return ts.Completions.getCompletionsAtPosition(host, program, log, getValidSourceFile(fileName), position, fullPreferences, options.triggerCharacter);
        }

where the getCompilerOptionsDiagnostics() call is finding program to be undefined even after calling synchronizeHostData.

This could be a bug in ts-loader, or it could be a bug in the ncc build of TypeScript, or some combination.

It may turn out to be some kind of instancing issue too with TypeScript, but we very carefully only have a single builtin version of TypeScript associated with the ts-loader build, unless there might be some missed dynamic import or something like that.

bug

All 5 comments

Did we update typescript or ts-loader between 0.18.5 or 0.20.1? I'm confused why this started happening recently 馃し鈥嶁檪

Yes, bisecting these upgrade paths will likely be the debugging technique :)

The break happens directly with https://github.com/zeit/ncc/pull/378 here unfortunately, so it is a bug in our build of TypeScript and ts-loader somehow in the new analysis rather than an upgrade path of either of those dependencies.

Reopening as we now get errors for internal definitions files here -

ncc: Version 0.20.2
ncc: Compiling file index.js
ncc: Using [email protected] (ncc built-in)
Error: [tsl] ERROR TS6053: File '/tmp/619ce465/.build-utils/.builder/node_modules/@zeit/ncc/dist/ncc/loaders/typescript/lib/lib.esnext.d.ts' not found.
[tsl] ERROR
      TS2318: Cannot find global type 'Array'.
[tsl] ERROR
      TS2318: Cannot find global type 'Boolean'.
[tsl] ERROR
      TS2318: Cannot find global type 'CallableFunction'.
[tsl] ERROR
      TS2318: Cannot find global type 'Function'.
[tsl] ERROR
      TS2318: Cannot find global type 'IArguments'.
[tsl] ERROR
      TS2318: Cannot find global type 'NewableFunction'.
[tsl] ERROR
      TS2318: Cannot find global type 'Number'.
[tsl] ERROR
      TS2318: Cannot find global type 'Object'.
[tsl] ERROR
      TS2318: Cannot find global type 'RegExp'.
[tsl] ERROR
      TS2318: Cannot find global type 'String'.
    at compiler.close.n (evalmachine.<anonymous>:1:1539399)
    at _promise0.then._result0 (eval at create (evalmachine.<anonymous>:1:273358), <anonymous>:13:1)
    at <anonymous>

Fixed in 0.20.4.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevage picture stevage  路  4Comments

paulogdm picture paulogdm  路  5Comments

omar2205 picture omar2205  路  5Comments

drewolson picture drewolson  路  3Comments

rauchg picture rauchg  路  3Comments