Overriding `tsconfig.json` for ts-node in mocha

前端 未结 8 2054
迷失自我
迷失自我 2020-12-13 23:38

Is it possible to override which tsconfig.json ts-node uses when called from mocha?

My main tsconfig.json contains \"module\": \"es20

相关标签:
8条回答
  • 2020-12-14 00:10

    While there doesn't seem to be a unified linux/windows command line phrasing that works, you can set the compiler-options from the command line. In my case, much like the OP, I have a tsconfig.json with a module: esnext. I was able to override on the command line:

    Ran on Windows, w/ts-node installed globally, but in different shell types:

    bash/mingw64:
    ts-node --compiler-options={"module":"commonJS"} xxx.ts

    cmd:
    ts-node --compiler-options={\"module\":\"commonJS\"} xxx.ts

    0 讨论(0)
  • 2020-12-14 00:13

    In package.json - scripts section:

    "test": "TS_NODE_PROJECT=src mocha"
    

    picks up my tsconfig.json in the src directory of my project, overriding the default tsconfig.json.

    OP can achieve same by using test instead of src

    0 讨论(0)
提交回复
热议问题