Skip to content

Commit

Permalink
fix: make tsconfig-paths work with comments in tsconfig.json (#588)
Browse files Browse the repository at this point in the history
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()`
  • Loading branch information
RafaelKr authored Sep 14, 2020
1 parent 5178a41 commit 987ca57
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 987ca57

Please sign in to comment.