question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing tsconfig.json with support for extra commas

See original GitHub issue

package.json

  "dependencies": {
    "ts-node": "^6.1.1",
    "tsconfig-paths": "^3.4.0",
    "typescript": "^2.9.2"
  },

run command ts-node -r tsconfig-paths/register.js test.ts

C:\Users\Cat\Desktop\toy-ts-node\node_modules\tsconfig-paths\lib\tsconfig-loader.js:72
    var config = JSON.parse(cleanedJson);
                      ^
SyntaxError: Unexpected token } in JSON at position 305
    at JSON.parse (<anonymous>)
    at loadTsconfig (C:\Users\Cat\Desktop\toy-ts-node\node_modules\tsconfig-paths\lib\tsconfig-loader.js:72:23)
    at loadSyncDefault (C:\Users\Cat\Desktop\toy-ts-node\node_modules\tsconfig-paths\lib\tsconfig-loader.js:27:18)
    at tsConfigLoader (C:\Users\Cat\Desktop\toy-ts-node\node_modules\tsconfig-paths\lib\tsconfig-loader.js:13:22)
    at Object.configLoader (C:\Users\Cat\Desktop\toy-ts-node\node_modules\tsconfig-paths\lib\config-loader.js:27:22)
    at Object.register (C:\Users\Cat\Desktop\toy-ts-node\node_modules\tsconfig-paths\lib\register.js:10:46)
    at Object.<anonymous> (C:\Users\Cat\Desktop\toy-ts-node\node_modules\tsconfig-paths\register.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)

I really use the command cross-env TS_NODE_PROJECT=./tool/tsconfig.json && ts-node -r tsconfig-paths/register ./node_modules/webpack/bin/webpack.js --config ./tool/config.webpack.dev.ts

cross-env TS_NODE_PROJECT=./tool/tsconfig.json && node -r tsconfig-paths/register webpack --config ./tool/config.webpack.dev.ts

I don’t know how to use it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
ZSkycatcommented, Jun 20, 2018

I know why.because my tsconfig.json uses jsonc. https://github.com/TypeStrong/ts-node/issues/409#issuecomment-398583581

But, tsc support jsonc. It would be better to have tsconfig-paths support jsonc.

{
    "compilerOptions": {
        "rootDir": ".",
        "outDir": "../dist/tool",
        "target": "esnext",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "strict": true,
        "types": ["node"],
    },
    "include": [
        "./**/*",
    ],
}
1reaction
JakobJingleheimercommented, Jul 28, 2018

@jonaskello done 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can you use a trailing comma in a JSON object?
No. The JSON spec, as maintained at http://json.org, does not allow trailing commas. From what I've seen, some parsers may silently allow them...
Read more >
tsconfig.json isn't strict JSON, what now? : r/typescript - Reddit
Any tools that are "doing it right" shouldn't be parsing the config file themselves, so I'd say go nuts with comments and trailing...
Read more >
JSON - JavaScript - MDN Web Docs
The JSON object contains methods for parsing JavaScript Object Notation ... Property names must be double-quoted strings; trailing commas are forbidden.
Read more >
JSON editing in Visual Studio Code
The mode also accepts trailing commas, but they are discouraged and the editor ... The JSON support shipped with VS Code supports all...
Read more >
JSON with Commas and Comments - Hacker News
Anything with support for machine-readable schemas, validation, and robust ... ruby's JSON.parse accepts comments (but not trailing commas) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found