Skip to content

Errors when using resolveJsonModule through tools (due to missing JSON in the list of supported extensions?)  #24932

Closed
@mbenadda

Description

@mbenadda

TypeScript Version: 2.9.1, 3.0.0-dev.20180609 with resolveJsonModule: true

Search Terms: JSON, resolveJsonModule, import JSON, getOptionsDiagnostics

Code

This only happens when using a tool that uses the API and not through tsc CLI, but I tracked it down through to code in TypeScript itself (see repo & explanations below).

Expected behavior:

Compiles, parses settings.json (whatever JSON file) properly.

Actual behavior:

Gets ts-loader to throw TypeError: Cannot read property 'getOptionsDiagnostics' of undefined due to missing program (undefined) in instance.

Digging deeper, I can get to this error emitted in TypeScript: Debug Failure. File /path/to/repo/settings.json has unknown extension.

See TypeStrong/ts-loader#793 for the full discussion until now and mostly this comment for the most TypeScript-related bit and a more complete explanation.

The issue can be solved by manually adding ".json" to the supportedTypescriptExtensionsForExtractExtension list (in https://github.com/Microsoft/TypeScript/blob/master/src/parser/utilities.ts#L7812): compilation goes through and we actually get an output file that contains the JSON data as it should.

NB: we've come to suspect this bug might originate in TypeScript, but even if it is in ts-loader, any pointers as to a cause and/or possible fix would be very welcome.

Playground Link:

Here is a very minimal GitHub repository that reproduces this behavior: https://github.com/mbenadda/ts-loader-issue-793-example-repo

Related Issues:

N/A

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions