我正在使用带有打字的Typescript 1.8,但我决定使用@types升级到typescript 2.8。我下载了@ types / node,但是控制台显示错误:
error TS2304: Cannot find name 'require'.
我的项目结构如下:
node_modules
src >
client
server >
tsconfig.ts
tsconfig.ts:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"typeRoots": [
"../node_modules/@types"
],
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "server",
"baseUrl": "."
},
"include": [
"src/**/*"
]
}
添加"types": ["node"]
无效
答案 0 :(得分:0)
根据您的目录结构,public class GoogleCategory
{
[Key]
public int Id { get; set; }
[Required, StringLength(250)]
public string Name { get; set; }
public bool Enabled { get; set; } = true;
}
public class Country
{
[Key]
public int Id { get; set; }
[Required, StringLength(250)]
public string Name { get; set; }
[Required, StringLength(2)]
public string Abbreviation { get; set; }
public bool Enabled { get; set; } = true;
}
选项的路径看起来不正确 - 它应该是tsconfig文件的相对路径。您的$Contents = Get-Content "Path\test.txt"
$list = @()
foreach($Line in $Contents) {
$Line = $Line.split(":")[1]
$s = $line -split ':'
$RegPath = $s[0]
$Value_Name = $s[1]
$Type = $s[2]
$Value = $s[3]
Write-host $RegPath $Value_Name $Type $Value
$list += @{Regpath=$Regpath;Name=$Value_Name;Type=$Type;Value=$Value}
}
目录比tsconfig的位置高2级,因此您的类型根应该是:
typeRoots
完整的tsconfig:
node_modules