Skip to content
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

Using the compiler API - typescript module experiences internal error #14722

Closed
ORESoftware opened this issue Mar 18, 2017 · 15 comments
Closed
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@ORESoftware
Copy link

ORESoftware commented Mar 18, 2017

On TS 2.2.1

I am following the instructions here:
https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

I am getting this error which is occurring within the TS source:

alexamil$ ./dev-server2.js 
/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:24044
                var resolvedFileName = result.resolvedModule && result.resolvedModule.resolvedFileName;
                                             ^

TypeError: Cannot read property 'resolvedModule' of undefined
    at Object.set (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:24044:46)
    at Object.resolveModuleName (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:24122:40)
    at loader_1 (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:63903:78)
    at loadWithLocalCache (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:63851:42)
    at resolveModuleNamesWorker (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:63904:88)
    at resolveModuleNamesReusingOldState (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:64018:24)
    at processImportedModules (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:64869:35)
    at findSourceFile (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:64779:17)
    at processSourceFile (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:64682:27)
    at processRootFile (/Users/alexamil/WebstormProjects/oresoftware/speedy-tsc/node_modules/typescript/lib/typescript.js:64570:13)

also as an aside, why isn't there any error handling here:

/// <reference path="typings/node/node.d.ts" />

import * as ts from "typescript";

function compile(fileNames: string[], options: ts.CompilerOptions): void {
    let program = ts.createProgram(fileNames, options);
    let emitResult = program.emit();

    let allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);

    allDiagnostics.forEach(diagnostic => {
        let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
        let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
        console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
    });

    let exitCode = emitResult.emitSkipped ? 1 : 0;
    console.log(`Process exiting with code '${exitCode}'.`);
    process.exit(exitCode);
}

compile(process.argv.slice(2), {
    noEmitOnError: true, noImplicitAny: true,
    target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
});

in other words - why do I not see either a try / catch or an error-first callback in your example code?

thanks

@ORESoftware ORESoftware changed the title Using the compiler API Using the compiler API - typescript module experiences internal error Mar 18, 2017
@ORESoftware
Copy link
Author

Seems like a bug within the typescript module, or perhaps the examples are outdated. It doesn't look like I am passing bad input, but if I were, it shouldn't crash like that.

@ORESoftware
Copy link
Author

ORESoftware commented Mar 18, 2017

What I am trying to do: Normally tsc -w would be OK, but I need to hook into tsc -w to know when it starts transpiling and when it's done transpiling, and I need to know which file was transpiled. I can do string matching on stdout from tsc -w but that isn't very robust + I need to know which file path change and tsc -w does not write that information out as is :(

@ORESoftware
Copy link
Author

looking to bump this one, thanks

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Mar 23, 2017

moduleNameResolver.ts line 458 needs to check if result isn't undefined:

        if (traceEnabled) {
            if (result.resolvedModule) { <---
                trace(host, Diagnostics.Module_name_0_was_successfully_resolved_to_1, moduleName, result.resolvedModule.resolvedFileName);

@mhegazy mhegazy assigned ghost Mar 24, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Mar 24, 2017

PRs appreciated.

@ghost
Copy link

ghost commented May 11, 2017

Actually, result should always be defined. (We really need --strictNullChecks.) Both nodeModuleNameResolver and classicNameResolver seem to always define it, so there may have been a bad moduleResolution.

@ORESoftware
Copy link
Author

ORESoftware commented Jun 17, 2017

Hey all, I am really looking for answers to this related issue

#16602

any help appreciated

@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.5 milestone Jun 18, 2017
@ghost
Copy link

ghost commented Jun 20, 2017

Hi @ORESoftware, can you still reproduce the original issue?

@ORESoftware
Copy link
Author

ORESoftware commented Jun 21, 2017

@andy-ms let me try it again, I haven't tried to get this to work in more than a month - however if there were a solution to this:

#16602

then the current issue thread would be obviated.

@ghost
Copy link

ghost commented Jul 12, 2017

@ORESoftware friendly ping

@the1mills
Copy link

Give me two days, let me try to reproduce again, thanks

@the1mills
Copy link

I am OREsoftware döppelgãngêr

@ghost
Copy link

ghost commented Aug 9, 2017

@ORESoftware ping

@ORESoftware
Copy link
Author

ah yes, I haven't gotten to this, I probably won't anytime soon, can you keep open? if not pls close as needed

@mhegazy
Copy link
Contributor

mhegazy commented Aug 16, 2017

closing for house keeping purposes. please reopen if issue still exists.

@mhegazy mhegazy closed this as completed Aug 16, 2017
@RyanCavanaugh RyanCavanaugh added Needs More Info The issue still hasn't been fully clarified and removed Bug A bug in TypeScript labels Dec 17, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

5 participants