Doesn't handle tsconfig.json with comments
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript, webpack
- Domain
- build-system
Research direction
Start by locating the source corresponding to lib/index.js and trace the two tsconfig.json reads shown in the issue. Review TypeScript's readConfigFile behavior and the supplied workaround, then verify that project-reference configs containing comments no longer produce a JSON parse error. Done means both alias-generation paths handle commented configs while preserving error handling.
Written by the indexing model from the issue text.
Description
The JSON parsing of tsconfig.json files doesn't seem to having comments in them, and errors with a JSON parse error.
Here's the patch I'm using to work around it (with patch-package):
diff --git a/node_modules/@microsoft/webpack-project-references-alias/lib/index.js b/node_modules/@microsoft/webpack-project-references-alias/lib/index.js
index f88fe3a..1d33585 100644
--- a/node_modules/@microsoft/webpack-project-references-alias/lib/index.js
+++ b/node_modules/@microsoft/webpack-project-references-alias/lib/index.js
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const functional_1 = require("./functional");
+const typescript = require("typescript");
+
function getAliasForProject(project) {
if (typeof project === "undefined") {
project = process.cwd();
@@ -33,7 +35,7 @@ const getReferencedProjectsRecursive = functional_1.memoize((tsConfigPath) => {
function getReferencedProjects(tsConfigPath) {
var _a;
const projectDir = path.dirname(tsConfigPath);
- const config = require(tsConfigPath);
+ const config = readConfigFile(tsConfigPath)
const references = (_a = config.references) === null || _a === void 0 ? void 0 : _a.map(o => o.path).map(p => path.join(projectDir, p)).map(resolveTsConfig);
return (references !== null && references !== void 0 ? references : []);
}
@@ -62,7 +64,7 @@ function tryGetPackageInfo(dir) {
}
function getAliasFor(tsConfigPath) {
const projectRootDir = path.dirname(tsConfigPath);
- const config = require(tsConfigPath);
+ const config = readConfigFile(tsConfigPath);
const hasExplicitOutDir = typeof config.compilerOptions.outDir !== "undefined";
const rootDir = path.join(projectRootDir, config.compilerOptions.rootDir || "");
const outDir = hasExplicitOutDir
@@ -82,3 +84,6 @@ function getAliasFor(tsConfigPath) {
alias[outDir] = rootDir;
return alias;
}
+function readConfigFile(tsConfigPath) {
+ return typescript.readConfigFile(tsConfigPath, path => fs.readFileSync(path, 'utf-8')).config
+}
It totally ignores errors which is naive, but good enough as a temporary workaround.
- Dominant language
- TypeScript
- Stars
- 22
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
comp/dashboard P3 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NousResearch/hermes-agent#117722 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·