ts-node似乎没有从typeRoots获取输入

问题描述

我正在使用打字稿进行Webpack配置。

我的tsconfig看起来像这样:

{
  "compilerOptions": {
    "module": "CommonJS","baseUrl": ".","target": "esnext","esModuleInterop": true,"allowSyntheticDefaultImports": true,"typeRoots": [
      "typings","node_modules/@types"
    ],"sourceMap": true,"types": [
      "node"
    ]
  },"include": ["src","typings"],"exclude": [
    "node_modules","../../../node_modules"
  ]
}

然后在我的类型输入/index.d.ts

import webpack from 'webpack';

declare global {
  namespace NodeJS {
    interface ProcessEnv {
      NODE_ENV: 'development' | 'production' | 'none';
      PROFILING?: string;
      SOURCE_MAP?: webpack.Options.Devtool;
      IMAGE_INLINE_SIZE_LIMIT: string;
      KIND: 'lib' | 'app' | 'shell';
      PUBLIC_PATH?: string;
      MAX_ASSET_SIZE: string;
      MAX_ENTRY_POINT_SIZE: string;
      OPTIMIZE?: 'optimize';
    }
  }
}

declare module 'dotenv-extended' {
  interface dotEnvExtended {
    load: (options: Partial<{
      encoding: string,silent: boolean,path: string,defaults: string,schema: string,errorOnMissing: boolean,errorOnExtra: boolean,errorOnRegex: boolean,includeProcessEnv: boolean,assignToProcessEnv: boolean,overrideProcessEnv: boolean
    }>) => void
  }
}

export {}

我正在使用VS代码,似乎可以很好地进行输入

vsCode picking up typings as "production" | "development" | "none"

但是,在运行实际的ts节点时,似乎正在使用来自global.d.ts的[key: string]: string | undefined;

我正在运行像这样的yarn cross-env TS_NODE_PROJECT=\"../dev-tools/tsconfig.json\" webpack --config ../dev-tools/src/webpack.config.ts

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)