首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么'exclude‘选项在tsconfig中不起作用?

为什么'exclude‘选项在tsconfig中不起作用?
EN

Stack Overflow用户
提问于 2021-10-01 08:37:55
回答 1查看 236关注 0票数 0

我正在nuxt + nest堆栈上写一个管理面板。

我使用这个模板:https://github.com/stephsalou/nuxt-nest-template

当我在本地工作时,没有与服务器相关的错误,但是当我运行mode build时,ts想要将node_modules中的文件原型化

Package.json

代码语言:javascript
复制
  "scripts": {
    "nuxt": "nuxt",
    "nest": "nest start",
    "dev": "cross-env NODE_TYPE=docker IS_NUXT_ENABLED=true nodemon",
    "dev:production": "cross-env NODE_TYPE=production IS_NUXT_ENABLED=true nodemon",
    "dev:client": "nuxt",
    "dev:server": "nodemon",
    "build": "NODE_TYPE=production run-s clean:dist compile:server compile:client client:generate copy:.nuxt copy:client copy:config",
    "clean:dist": "rimraf dist",
    "compile:server/*this script throws an error*/": "tsc --listFiles -p tsconfig.build.json",
    "compile:client": "cross-env mode=production nuxt build",
    "client:generate": "cross-env mode=production nuxt generate",
    "copy:client": "copyfiles -a \\\"client/**/*\\\" dist",
    "copy:.nuxt": "copyfiles -a \".nuxt/**/*\" dist",
    "copy:config": "copyfiles nuxt.config.ts package.json package-lock.json dist",
    "analytics:dev": "NODE_ENV=development webpack --watch --config ./static/js/analytics/webpack",
    "analytics:build": "NODE_ENV=production webpack --config ./static/js/analytics/webpack"
  },

tsconfig

代码语言:javascript
复制
{
  "compilerOptions": {
    "target": "ES2017",
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "outDir": "./dist/server",
    "baseUrl": "./",
    "skipLibCheck": true,
    // "incremental": true,
    "lib": ["ESNext", "ESNext.AsyncIterable", "DOM"],
    // "esModuleInterop": true,
    // "allowJs": true,
    // "strict": true,
    // "noEmit": true,
    "paths": {
      "~/*": ["./server/*"],
      "@/*": ["./client/*"]
    },
     "types": ["@types/node", "@nuxt/types", "@types/sequelize"]
  },
  "exclude": ["node_modules/**/*", ".nuxt", "dist"]
}

tsconfig.build

代码语言:javascript
复制
{
  "extends": "./tsconfig.json",
  "include": [
    "server/**/*"
  ]
}

为什么它可能不起作用?

EN

回答 1

Stack Overflow用户

发布于 2021-10-01 09:00:36

我不认为这与tsconfig有任何关系。库应该包含在编译中,因为它们是应用程序的一部分。添加属性

代码语言:javascript
复制
"skipLibCheck": true

是这类错误的多次修复,因为它跳过了对*.d.ts(库文件)的检查。但不是你的情况,因为它在那里。

首先,我会检查节点版本、纱线版本等。

我使用yarn build成功地试用了该模板

代码语言:javascript
复制
node v14.7.0
yarn v1.22.15

然后我觉得includeexclude看起来有点奇怪。如果我没记错的话,扩展时includeexclude会被覆盖。因此,您可能需要在两个配置文件中显式指定它们。

I.e

在tsconfig.json中

代码语言:javascript
复制
"exclude": ["node_modules", ".nuxt", "dist"]

在tsconfig.build.json中(确保排除测试)

代码语言:javascript
复制
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"],
"include": ["server"]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69402934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档