I tried all suggestions in this thread to-date, including setting resolveJsonModule to true, moduleResolution to "node", and various formats of the include statement (assert/with) and require. I also closed and restarted VSCode between most changes. Nothing here worked.
But from my ./src/index.ts, I did get import metadata from './block.json
working and with no other errors, by setting the tsconfig.json include
parameter to ["src"]
, and setting "files":["src/block.json"]
. Note that the JSON file is not in the rootDir.
Interestingly (to me anyway) even when the './block.json' was getting the red squigglies, Intellisense on 'metadata' showed all of the properties defined in the JSON. I do not have a declaration of the schema in this project. So VSCode recognized the file and processed its contents even though TS flagged the error.
I don't know if this is version-specific. In this project I have TypeScript 5.3.3, @types/node 20.11.24, and the tsconfig.json below. From rootDir, my src folder has all source, processed by WebPack into ./build. (The reference to ./dist is there in case TypeScript needs a different outDir than WebPack.
I can't say this is THE solution for anyone else, or that other solutions might be more elegant for my own purposes or others, only that this configuration absolutely works as A solution for me at this moment.
{
"compilerOptions": {
"composite": true,
"target": "ES2022",
"lib": ["ES2022", "ES2022.String", "DOM", "DOM.Iterable"],
"jsx": "react-jsx",
"useDefineForClassFields": true,
"module": "ES2022",
"moduleResolution": "bundler",
"types": ["node"],
"resolveJsonModule": true,
"allowJs": true,
"checkJs": true,
"outDir": "./dist",
"preserveConstEnums": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"skipLibCheck": true
},
"include": ["src"],
"files": ["src/block.json"]
}