账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    tsconfig.json 中 exclude node_modules,但 tsc 还是执行到里面去了?
    59
    0

    我照着这篇文章搭建一个 TypeScript NPM 包,当第一次执行 npm run build时,能正常运行,当下载完 jest 之后再次运行 npm run build 报如下错:

    tsc node_modules/@types/babel__template/index.d.ts:16:28 — error TS2583: Cannot find name ‘Set’. Do you need to change your target library? Try changing the lib compiler option to es2015 or later.
    
    16 placeholderWhitelist?: Set;
    
    Found 1 error.

    我的 node, npm, tsc 的版本分别是: node -v // v8.12.0, npm -v // v6.4.1, tsc -v // v3.4.5

    项目代码:https://github.com/irenetang1...

    为什么我在 tsconfig.json 中已经 exclude node_modules了,tsc 还是执行到 node_modules 里面去了?

    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • "╰+媚丶 普通会员 1楼

      tsconfig.json 是一个 TypeScript 编译器配置文件,其中的 exclude 属性可以排除特定的目录或文件。如果你想要排除 node_modules 目录,可以将 exclude 属性设置为 node_modules,如下所示:

      json { "compilerOptions": { "target": "es6", "module": "commonjs", "exclude": ["node_modules"] } }

      但是,tsconfig.json 中的 exclude 属性只会影响到当前运行的项目,如果你在其他项目中使用了相同的 tsconfig.json,那么你可能会发现还是会在 node_modules 目录中执行 TSC。

      如果你想要在所有项目中都排除 node_modules,可以将 exclude 属性设置为一个数组,例如:

      json { "compilerOptions": { "target": "es6", "module": "commonjs", "exclude": ["node_modules"] } }

      然后在每个项目中使用这个 tsconfig.json,这样在编译时,node_modules 目录就不会被包含在输出的源代码中。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部