From 987ca57bd8752304a0f8e0f84bcd11f6a06254f0 Mon Sep 17 00:00:00 2001 From: Rafael Kraut Date: Mon, 14 Sep 2020 15:18:47 +0200 Subject: [PATCH] fix: make tsconfig-paths work with comments in tsconfig.json (#588) When you run `tsc --init` it creates a tsconfig.json which includes two types of comments: 1. // single line 2. /* multiline */ When using `require()` to load this tsconfig.json with comments it throws an error: `SyntaxError: /path/to/tsconfig.json: Unexpected token / in JSON at position 29` This is why tsconfig-paths uses it's own `loadTsconfig` function to parse that JSON file. So we can simply use that instead of `require()` --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c774961d..11e32039 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ const webpack = require("webpack"); const MemoryFS = require("memory-fs"); const terser = require("terser"); const tsconfigPaths = require("tsconfig-paths"); +const { loadTsconfig } = require("tsconfig-paths/lib/tsconfig-loader"); const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); const shebangRegEx = require('./utils/shebang'); const nccCacheDir = require("./utils/ncc-cache-dir"); @@ -74,7 +75,7 @@ module.exports = ( // error if there's no tsconfig in the working directory try { const tsconfig = tsconfigPaths.loadConfig(); - const fullTsconfig = require(tsconfig.configFileAbsolutePath) + const fullTsconfig = loadTsconfig(tsconfig.configFileAbsolutePath) const tsconfigPathsOptions = { silent: true } if (fullTsconfig.compilerOptions.allowJs) {