我在 [1,1] 处的 tsconfig.json 文件中收到此错误六次:
Cannot find type definition file for 'body-parser'.
The file is in the program because:
Entry point for implicit type library 'body-parser'
Run Code Online (Sandbox Code Playgroud)
我真的不确定为什么会收到此错误,更不用说六次了。任何帮助将不胜感激。
这是我的 tsconfig:
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Projects */
// "incremental": true, /* Enable incremental compilation */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo …
Run Code Online (Sandbox Code Playgroud) 我试过这些
我的打字和@ types/node似乎已正确安装.以下是错误详细信息:
/Users/ishandutta2007/Documents/Projects/myproj/node_modules/aws-sdk/lib/http_response.d.ts(1,25)中的错误:找不到模块'stream'.)/ Users/ishandutta2007/Documents/Projects/myproj /node_modules/aws-sdk/lib/http_response.d.ts(1418):找不到名称'Buffer'.)
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
的package.json
{
"name": "reactvidsangular",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "webpack-dev-server --port=4200",
"build": "webpack",
"test": "karma start ./karma.conf.js",
"lint": "ng lint",
"e2e": "protractor ./protractor.conf.js",
"prepree2e": "npm start",
"pree2e": "webdriver-manager update --standalone false --gecko …
Run Code Online (Sandbox Code Playgroud) amazon-web-services typescript tsconfig typescript-typings angular
这个问题在解决方案简单添加的许多地方也出现过类似的问题
import { } from '@types/googlemaps';
Run Code Online (Sandbox Code Playgroud)
这是过去版本的角度解决方案.现在出现的问题是我使用的是Angular 6+
TS2304: Cannot find name 'google'.
TS2503: Cannot find namespace 'google'.
Run Code Online (Sandbox Code Playgroud)
有很多这样的错误,但它发生在每一行,如:
let place: google.maps.places.PlaceResult = autocomplete.getPlace();
Run Code Online (Sandbox Code Playgroud)
我可以通过插入// @ts-ignore
使用谷歌地图的所有行来快速解决问题,但我对真正的修复更感兴趣.但是这个有用的事实让我觉得这是一个tsconfig问题,我对此并不十分自信.
我可以确认googlemaps是安装在node_modules/@ types中的,但是
ts.config
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"typeRoots": [
"node_modules/@types",
],
"lib": [
"es2017",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个Stackblitz示例,如果您查看控制台,则会引发参考错误.我不知道下一步该尝试什么.
我已经安装了TypeScript 1.8.2,并使用了Visual Studio 2015.我有一个简单的项目,我在排除tsconfig.json文件中的文件夹时遇到问题.问题是我想排除文件typings/browser.d.ts和文件夹typings/browser.但这种情况并非如此?
我没有问题排除子文件夹,但不是子文件夹?
[注意]我刚刚意识到问题出现在我从Visual Studio构建时!如果我使用命令行中的tsc构建,则没有问题.我可以在Visual Studio中使用另一个版本的TypeScript吗?我怎么检查这个?
这是我的tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"public",
"typings/browser",
"typings/browser.d.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
我有一个更大的项目,我使用jspm并需要排除jspm包文件夹,该文件夹位于public的子文件夹中.
编辑 1:将 GitHub URL 添加到项目中
编辑2:删除baseUrl
修复tsconfig.json
所有问题并使用相对导入效果很好。
链接:Github
如何生成带有相对路径而不是 的打字稿声明文件alias
?
我正在 UMD 模式下创建一个库(samplelibrary)并将其发布到 npm 中。打包的 npm 库只有build
文件夹(带有类型),package.json
并且README.md
当我尝试在另一个打字稿应用程序中使用该库时,由于生成的类型声明文件无效,构建失败。类型声明文件包含别名而不是相对路径。
编译日志:
ERROR in /workspace/myproject/node_modules/samplelibrary/build/typings/src/foo.d.ts(403,17):
TS2307: Cannot find module 'utils/bar
如何解决这个问题?
实际创建的声明文件foo.d.ts:
declare const Foo: {
bar: typeof import("utils/bar");
}
Run Code Online (Sandbox Code Playgroud)
预期文件:
declare const Foo: {
bar: typeof import("./utils/bar");
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"sourceMap": true,
"rootDir": "./",
"baseUrl": "./src",
"paths": {
"@samplecompany/sampleproject": ["./"]
}, …
Run Code Online (Sandbox Code Playgroud) 如何config.json
在我的 Typescript 项目中使用内部?
为清楚起见:
我有一个根/config.json
如下:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"inlineSourceMap": true,
"outDir": "./app/",
"lib": [
"es6"
],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"baseUrl": "./",
"noImplicitAny": true,
"skipLibCheck": true,
"paths": {
"*": [
"types/*"
]
}
},
"include": [
"./src/**/*.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
我想拥有/innerFolder/config.json
以下内容:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noImplicitReturns": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
}
}
Run Code Online (Sandbox Code Playgroud)
我这样做是因为我想对团队的代码进行重构,但它很大,我不想一次更改我的所有文件。
我想逐个文件夹执行此操作,并使用更改“锁定”文件夹。
根据文档,编译器会查找 parent tsconfig.json
,但不会查找特定的tsconfig.json
.
有没有办法做到这一点?
我的代码库包含两个打字稿项目:
Web Worker 代码库是我的public/
文件夹的一部分。这意味着同一个工作区中有两个打字稿项目。我怎样才能使这个与 vs-code 一起工作?
到目前为止,我的问题基本上是重复的:How to use multiple tsconfig files in vs-code?
接受的答案解释了如何设置基本配置然后扩展它:
//tsconfig.worker.json:
{
"extends": "./tsconfig.json",
"exclude": [
"src/app"
]
}
Run Code Online (Sandbox Code Playgroud)
但这对我来说不起作用。对于worker.ts
我需要lib
与反应应用程序不同的配置。
可以覆盖 my 中的配置tsconfig.worker.json
并使用新设置进行编译。但对于自动补全和错误高亮,vs-code 只使用了tsconfig.json
,这与 webworker 源代码不兼容。
tsconfig.json需要什么才能在Chrome中运行?所以我只需运行tsc然后可以在浏览器中查看该文件,并在控制台中显示相应的结果?
index.html包含:
<!DOCTYPE html>
<html>
<head><title>TypeScript app</title></head>
<body>
<script src="dist/app.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
index.ts包含
import { alpha } from "alpha";
import { beta } from "beta";
console.log(alpha + " " + beta);
Run Code Online (Sandbox Code Playgroud)
alpha包含
export const alpha = 'alpha';
Run Code Online (Sandbox Code Playgroud)
beta包含
export const beta = 'beta';
Run Code Online (Sandbox Code Playgroud)
入口点是index.ts,我希望它们都捆绑在一个名为app.js的文件中.
有没有办法如何设置tsconfig.json
环境特定的,例如tsconfig.prod.json
和tsconfig.dev.json
?
我想在开发环境中拥有sourceMap
和comments
,但我想在生产环境中删除这些。
情况如下。我正在使用 Nrwl NX Monorepo。我有 2 个库:lib-a
和lib-b
; 两者都是通过 NX 创建的可发布库。
现在我创建一个MyClass.ts
在lib-a
. workspace/tsconfig.json
当然,在> NX中的路径下paths
会为此创建一个别名lib-a
( "@workspace/lib-a": ["libs/lib-a/src/index.ts"]
)。
到目前为止,一切都很好。现在我们可以通过导入它在工作区/monorepo 中的任何地方使用这个类import { MyClass } from '@workspace/lib-a';
不幸的是我们无法构建lib-b
正在导入的MyClass
. 当我们尝试这样做时,我们会收到以下错误。那么问题是我们如何构建lib-b
?
PS:奇怪的是,NX monorepo 实际上不支持链接 2 个可发布库的常见场景。
“错误 TS6059:文件“d:/workspace/libs/lib-a/src/index.ts”不在“rootDir”下“d:\workspace\libs\lib-b\src”rootDir 预计包含所有源文件”
tsconfig ×10
typescript ×9
angular ×2
reactjs ×2
body-parser ×1
environment ×1
javascript ×1
monorepo ×1
namespaces ×1
nrwl ×1
nrwl-nx ×1
ts-loader ×1
web-worker ×1