标签: tsconfig

如何在tsconfig.json中使用路径?

我正在阅读有关路径映射的内容tsconfig.json,我想使用它来避免使用以下丑陋的路径:

在此输入图像描述

项目组织有点奇怪,因为我们有一个包含项目和库的单一存储库.项目按公司和浏览器/服务器/通用分组.

在此输入图像描述

如何配置路径tsconfig.json而不是:

import { Something } from "../../../../../lib/src/[browser/server/universal]/...";
Run Code Online (Sandbox Code Playgroud)

我可以用:

import { Something } from "lib/src/[browser/server/universal]/...";
Run Code Online (Sandbox Code Playgroud)

webpack配置中还需要其他东西吗?还是tsconfig.json足够了?

node-modules typescript tsconfig

123
推荐指数
11
解决办法
9万
查看次数

为什么 Vite 会创建两个 TypeScript 配置文件:tsconfig.json 和 tsconfig.node.json?

我正在使用 Vite 创建一个新的 React + TypeScript 项目

创建项目后,根文件夹中有两个 TypeScript 配置文件:tsconfig.jsontsconfig.node.json. 以下是每一篇的内容:

tsconfig.json

{
    "compilerOptions": {
        "target": "ESNext",
        "useDefineForClassFields": true,
        "lib": ["DOM", "DOM.Iterable", "ESNext"],
        "allowJs": false,
        "skipLibCheck": false,
        "esModuleInterop": false,
        "allowSyntheticDefaultImports": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "module": "ESNext",
        "moduleResolution": "Node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": true,
        "jsx": "react-jsx"
    },
    "include": ["src"],
    "references": [{ "path": "./tsconfig.node.json" }]
}
Run Code Online (Sandbox Code Playgroud)

tsconfig.node.json

{
    "compilerOptions": {
        "composite": true,
        "module": "esnext",
        "moduleResolution": "node"
    },
    "include": ["vite.config.ts"]
}
Run Code Online (Sandbox Code Playgroud)

为什么我们需要两个?

第二个是做什么的?

我可以删除第二个吗?

javascript typescript tsconfig vite

101
推荐指数
2
解决办法
4万
查看次数

使用“react-jsx”作为带有 create-react-app 的 jsx 值的 Visual Studio Code 问题

我正在努力解决 VSCode 中的“错误”:

Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'
Run Code Online (Sandbox Code Playgroud)

因此,当value 似乎有效时,react-scripts (create-react-app) 会自动将jsxkey设置为react-jsxvalue react

实际上,代码运行良好并显示了我想要的页面,但是 IDE 将所有内容都强调为错误,并说:

Cannot use JSX unless the '--jsx' flag is provided.
Run Code Online (Sandbox Code Playgroud)

这是我的 tsconfig.json :

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
} …
Run Code Online (Sandbox Code Playgroud)

jsx typescript tsconfig visual-studio-code create-react-app

73
推荐指数
3
解决办法
2万
查看次数

打字稿 - tsconfig中的目标是什么?

我对Typescript很新.tsconfig.json中的Target表示什么?

{
  "compilerOptions": 
  {
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "moduleResolution": "classic",
    "lib": [ "es2015", "dom",  "es2017" ]
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript transpiler typescript tsconfig

55
推荐指数
2
解决办法
2万
查看次数

(ESLint/Cypress):解析错误:ESLint 被配置为使用“parserOptions.project”在“<tsconfigRootDir>/component/TestComponent.cy.ts”上运行

我正在使用 Remix (remix.run) 设置一个新项目,并尝试配置 Cypress/ESLint 进行组件测试。我有TestComponent.cy.ts一些样板代码:

describe('TestComponent.cy.ts', () => {
  it('playground', () => {
    // cy.mount()
  })
})
Run Code Online (Sandbox Code Playgroud)

但是,该describe函数会抛出此错误:

    Parsing error: ESLint was configured to run on `<tsconfigRootDir>/component/TestComponent.cy.ts` using `parserOptions.project`: <tsconfigRootDir>/../../../../../../users/tduke/desktop/dev/blog/cypress/tsconfig.json
    However, that TSConfig does not include this file. Either:
    - Change ESLint's list of included files to not include this file
    - Change that TSConfig to include this file
    - Create a new TSConfig that includes this file and include it in your parserOptions.project

Run Code Online (Sandbox Code Playgroud)

我尝试重新配置我的 …

typescript reactjs tsconfig remix typescript-eslint

48
推荐指数
4
解决办法
8万
查看次数

使用spec/test文件夹设置tsconfig

假设我把我的代码放在下面src并测试spec:

+ spec
+ --- classA.spec.ts
+ src
+ --- classA.ts
+ --- classB.ts
+ --- index.ts
+ tsconfig.json
Run Code Online (Sandbox Code Playgroud)

我只想转发srcdist文件夹.既然index.ts是我的包的入口点,我的tsconfig.json样子如下:

{
  "compileOptions": {
    "module": "commonjs"
    "outDir": "dist"
  },
  "files": {
    "src/index.ts",
    "typings/main.d.ts"
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,这tsconfig.json不包括测试文件,因此我无法解析其中的依赖项.

另一方面,如果我将测试文件包含在内,tsconfig.json那么它们也会被转换为dist文件夹.

我该如何解决这个问题?

typescript tsconfig visual-studio-code

43
推荐指数
3
解决办法
2万
查看次数

在mocha中覆盖ts节点的`tsconfig.json`

是否有可能覆盖tsconfig.json从mocha调用时使用的ts节点?

我的主要tsconfig.json包含"module": "es2015",但我只想"module": "commonjs"用于ts节点.

我试过这个

mocha --compilers ts:ts-node/register,tsx:ts-node/register \
    --compilerOptions '{"module":"commonjs"}' \
    --require ts-node/register test/**/*.spec.ts*
Run Code Online (Sandbox Code Playgroud)

但它不起作用:

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Module.m._compile (/usr/lib/node_modules/ts-node/src/index.ts:406:23)
    at Module._extensions..js (module.js:422:10)
    at Object.require.extensions.(anonymous function) [as .tsx] (/usr/lib/node_modules/ts-node/src/index.ts:409:12)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at /usr/lib/node_modules/mocha/lib/mocha.js:222:27
    at Array.forEach (native)
    at Mocha.loadFiles (/usr/lib/node_modules/mocha/lib/mocha.js:219:14)
    at Mocha.run (/usr/lib/node_modules/mocha/lib/mocha.js:487:10)
    at Object.<anonymous> (/usr/lib/node_modules/mocha/bin/_mocha:458:18)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load …
Run Code Online (Sandbox Code Playgroud)

mocha.js node.js tsconfig

36
推荐指数
5
解决办法
1万
查看次数

找不到在 tsconfig `paths` 中定义的模块

我正在尝试为我的模拟服务器设置别名。每当我尝试编译ts文件时,它都会返回找不到正确模块的错误,即使这些模块是在tsconfig,json->中定义的paths

文件夹结构:

??? server
?   ??? src
?       ???/json
??? src
?   ???/modules
??? tsconfig.json
Run Code Online (Sandbox Code Playgroud)

这是我的 tsconfig.json

{
    "compilerOptions": {
        "baseUrl": "./src",
        "experimentalDecorators": true,
        "jsx": "react",
        "lib": [
            "dom",
            "es2015",
            "es2015.promise"
        ],
        "module": "commonjs",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "noUnusedLocals": true,
        "esModuleInterop": true,
        "paths": {
            "@project/app/modules/*": [
                "modules/*"
            ],
            "@project/server/data/*": [
                "../server/src/json/*"
            ]
        },
        "sourceMap": true,
        "target": "es5"
    },
    "exclude": [
        "node_modules",
        "tools"
    ]
}
Run Code Online (Sandbox Code Playgroud)

错误: Error: Cannot find module '@project/server/data/accounts/accountsList'

alias typescript tsc tsconfig ts-node

35
推荐指数
7
解决办法
5万
查看次数

如何使用多个tsconfig文件?

我正在使用Visual Studio Code并且具有相当常见的项目结构:

??? client/
?   ??? tsconfig.json
??? shared/
??? server/
?   ??? tsconfig.json
??? project.json
Run Code Online (Sandbox Code Playgroud)

这两个tsconfig文件具有不同的设置(例如,client/目标ES5 下的设置,server/目标ES6下的设置).

问题是我希望共享目录包含在两个项目中.我不能使用tsconfig这样做,因为该exclude选项不允许我包含一个比tsconfig.json更高的目录中的文件夹,并且使用files我必须不断保持文件列表是最新的,因为它不支持全球.

请注意,我可以通过将共享文件夹添加到tsc中来编译,我想要的是Visual Studio Code IDE识别intellisense的共享代码等.

是等待filesGlob的唯一选择吗?

typescript tsconfig visual-studio-code

32
推荐指数
4
解决办法
2万
查看次数

node_modules/@types/node/index.d.ts(20,1): 错误 TS1084: 无效的“引用”指令语法

我有打字稿编译的问题。smbd 遇到过吗?

node_modules/@types/node/index.d.ts(20,1): 错误 TS1084: 无效的“引用”指令语法。

tsconfig.json:

{
    "compileOnSave": false,
    "compilerOptions": {
        "sourceMap": true,
        "outDir": "./dist",
        "rootDir": "./app",
        "target": "es6",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "listFiles": false,
        "skipLibCheck": true
    },
    "include": [
        "./app/**/*.ts"
    ]
}
Run Code Online (Sandbox Code Playgroud)

package.json 中的打字稿版本: "typescript": "^2.6.1"

compilation node.js typescript tsconfig

31
推荐指数
6
解决办法
3万
查看次数