'package.json' is not under 'rootDir'

前端 未结 4 1082
醉梦人生
醉梦人生 2020-11-29 10:56

I\'m trying to import package.json in my TypeScript application:

import packageJson from \'../package.json\';

My tsconfi

4条回答
  •  醉酒成梦
    2020-11-29 11:46

    It depends on how and when you're reading "package.json". You can read it as file with NodeJS "fs" module at runtime, or just type const package = require("package.json").

    In 2nd case Typescript will search it in root dir at compile time (refer to Typescript module resolution documentation).

    You also can use "rootDirs" property instead of "rootDir" to specify array of root folders.

提交回复
热议问题