error TS6059: File ‘/root/project/packages/server/package.json‘ is not under ‘rootDir’ ‘/root/project/packages/server/src‘. ‘rootDir’ is expected to contain all source files.

Broken Code ❌

import pkg from '../../../../package.json';

Fixed Code ✔️

When using require then we can access files outside the specified root folder for input files (“rootDir” in “tsconfig.json”):

const pkg = require('../../../../package.json');

An even better solution would be changing the “rootDir” in your “tsconfig.json”, so that it includes the “package.json” file that you are trying to important. This may require you to also set “allowJs” to true in your “tsconfig.json”.