TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs', 'amd', 'es2015' or 'esNext'

Open ashubham opened this issue 6 years ago • 2 comments

TypeScript Version: 3.4.3

Search Terms: TS5071

Expected behavior: Should compile for module: 'system'. I use a json-loader plugin within systemJS to load these json files. Earlier we used the .d.ts for json but with the latest upgrade it fails with the above error.

Related Issues: https://github.com/Microsoft/TypeScript/issues/26224

ashubham avatar Apr 16 '19 22:04 ashubham

If I see correctly, I also faced this one, and wondered why, any recomendations on how to make node16 tsconfig work with resolveJsonModule, module amd seems the only fit.

I know this is not a full reprex but represents the gist of it, see below

tsc --version
Version 5.0.4
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "extends": ["@tsconfig/node16/tsconfig.json"],

  "compilerOptions": {
    "outFile": "dist/bundle.js",
    "incremental": true,
    // amd compiles ok
    // "module": "AMD",

    // system throws an error
    "module": "System",
    "resolveJsonModule": true
  },
  "include": ["src"]
}

tsconfig.json:11:5 - error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs', 'amd', 'es2015' or 'esNext'.

11     "module": "System",
       ~~~~~~~~

tsconfig.json:12:5 - error TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs', 'amd', 'es2015' or 'esNext'.

12     "resolveJsonModule": true
       ~~~~~~~~~~~~~~~~~~~

If one decides to use "module": "commonjs", you will get.

tsconfig.json:6:5 - error TS6082: Only 'amd' and 'system' modules are supported alongside --outFile.

FrancescElies avatar May 04 '23 08:05 FrancescElies

In short trying to use resolveJsonModule with outFile with node16's tsconfig seems to be quite complicated, any help appreciated, thanks in advance.

FrancescElies avatar May 04 '23 09:05 FrancescElies