tsconfig和ts-node的模块假设的范围

时间:2018-06-06 20:06:18

标签: typescript ts-node

我倾向于在TypeScript中编写构建/部署脚本,然后使用ts-node运行它们。这已经很好地工作了很长一段时间,但我最近做了两件事,把一个猴子的扳手扔进了东西:

  1. 我升级到TS 2.9(这可能是红鲱鱼)
  2. 我将我的转换转换为ES2015模块系统(来自CJS)
  3. 我强烈怀疑第2项让我感到悲伤,但让我快速解释悲伤。我有一个scripts/build.ts脚本,开头有一些像这样的导入:

    // tslint:disable:no-implicit-dependencies
    import chalk from "chalk";
    import { exec, asyncExec } from "async-shelljs";
    import rm from "rimraf";
    import * as process from "process";
    

    这一直没有问题,但现在我收到以下错误:

      

    从“粉笔”导入粉笔; SyntaxError:意外的令牌导入

    我强烈建议ts-node不期待ES2015模块语法。这是我目前的tsconfig.json

    {
      "compilerOptions": {
        "declaration": true,
        "module": "es2015",
        "target": "es2015",
        "lib": ["es2015", "esnext.asynciterable", "es2015.reflect"],
        "moduleResolution": "node",
        "sourceMap": true,
        "noImplicitAny": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "outDir": "./lib",
        "removeComments": false,
        "typeRoots": ["./node_modules/@types"]
      },
      "include": ["src/**/*"],
      "exclude": ["node_modules/**/*", "node_modules/firemock/**"]
    }
    

    我一直对tsconfig文件的“范围”有点困惑。在某些方面,因为这个文件位于/scripts文件夹中,因此在“包含”路径之外,我认为它无论如何都会超出范围。但显然情况并非如此,因为当我将module切换回“commonjs”时,我的脚本运行得很好。

    为什么会这样?

0 个答案:

没有答案