Definitelytyped: エラーTS2304:名前'Set'が見つかりません。 815 allowedNodeEnvironmentFlags:設定<string>;</string>

作成日 2018年09月25日  ·  20コメント  ·  ソース: DefinitelyTyped/DefinitelyTyped

D:\workshop\www
λ node -v
v8.12.0

D:\workshop\www
λ npm -v
6.4.1

D:\workshop\www
λ npm install typescript -g
C:\Users\dell\AppData\Roaming\npm\tsc -> C:\Users\dell\AppData\Roaming\npm\node_modules\typescript\bin\tsc
C:\Users\dell\AppData\Roaming\npm\tsserver -> C:\Users\dell\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
+ [email protected]
updated 1 package in 3.061s

D:\workshop\www
λ tsc --version
Version 3.0.3

D:\workshop\www
λ mkdir typescript_learning

D:\workshop\www
λ cd typescript_learning

D:\workshop\www\typescript_learning
λ npm init -y
Wrote to D:\workshop\www\typescript_learning\package.json:

{
  "name": "typescript_learning",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}



D:\workshop\www\typescript_learning  ([email protected])
λ tsc --init
message TS6071: Successfully created a tsconfig.json file.

D:\workshop\www\typescript_learning  ([email protected])
λ npm install @types/node --dev-save
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ @types/[email protected]
added 1 package from 30 contributors in 1.657s

D:\workshop\www\typescript_learning  ([email protected])
λ touch helloworld.ts

D:\workshop\www\typescript_learning  ([email protected])
λ tsc helloworld.ts
node_modules/@types/node/index.d.ts:815:38 - error TS2304: Cannot find name 'Set'.

815         allowedNodeEnvironmentFlags: Set<string>;

helloworld.ts

var a:string = "HelloWorld"
console.log(a)

私は何をすべきか?

最も参考になるコメント

ここでは、 targetlibes6と同じです。
@types/[email protected]をインストールすることで、これを修正することができました。

全てのコメント20件

"lib": ["es6"]以上を追加します。

同じ問題が発生していますが、 tsconfigファイルにlibオプションを追加しても解決しませんでした。

Typescriptバージョン:3.1.1
ノードタイピングバージョン:10.11.5

再現する手順

$ mkdir test
$ cd test
$ npm init -y
$ npm install --save-dev typescript @types/node
$ echo 'console.log("test")' > index.ts
$ ./node_modules/.bin/tsc --init

Add lib: "es2015" to tsconfig.json

$ ./node_modules/.bin/tsc index.ts

node_modules/@types/node/index.d.ts:815:38 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

815         allowedNodeEnvironmentFlags: Set<string>;

私はこれについて多くの人に話しました、 libがそれを修正しない場合、ある時点でtsconfigが正しくロードされていない場合は、 includeを使用してlibがファイルと一緒に正しくロードされていることを確認してくださいtsconfig.jsonのfilesオプション。

@ andy-ms Setの変更を元に戻す必要がありますか?
人々は実際にはノードで使用するために>es6 libを使用する必要がありますが、これは重大な変更と見なされる可能性があります。

--lib es5で機能するように、 node/index.d.tsinterface SetConstructor {} $の下に$ interface Set<T> {}を定義できると思います。

同じ問題。

☁  jest-codelab [master] ⚡  $(npm bin)/tsc ./src/@types/index.ts
node_modules/@types/node/index.d.ts:815:38 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

815         allowedNodeEnvironmentFlags: Set<string>;
                                         ~~~

tsconfig.json

"lib": ["es2015", "es2016"]

package.json

"devDependencies": {
    "@types/jest": "^23.3.3",
    "@types/node": "^10.11.4",
    "jest": "^23.6.0",
    "ts-jest": "^23.10.4",
    "tslint": "^5.11.0",
    "typescript": "^3.1.1"
  }

@mrdulin allowedNodeEnvironmentFlags: ReadonlySet<string>;があり、 interface ReadonlySet<T> {}@types/node/index.d.tsで宣言されているため、最新の@types/nodeがインストールされていないことがわかります(現在は10.12.0)。 @types/node/index.d.ts

@andy-msありがとう。 npm rm @types/node -Dの後、この問題はなくなりました。

同じ問題があり、 tsconfig.jsoncompilerOptions.typesを使用して解決します。 したがって、基本的には、そのプロパティに必要な@typesパッケージのみをリストしました。

@ rannie-peraltaこの問題は、空のReadonlySet宣言を行うことで、タイプが長い間修正されています。

私も同じような問題に遭遇しました。
package.json
{{
"名前": "地図"、
「バージョン」:「1.0.0」、
"説明": ""、
"main": "index.js"、
"スクリプト":{
"test": "echo \"エラー:テストが指定されていません\" && exit 1"
}、
「キーワード」:[]、
"著者": ""、
「ライセンス」:「ISC」、
「依存関係」:{
"typescript": "^ 3.4.5"
}
}
tsconfig.json
{{
"compilerOptions":{
"モジュール": "amd"、
"noImplicitAny":true、
"esModuleInterop":true、
"sourceMap":true、
"jsx": "react"、
"jsxFactory": "tsx"、
"ターゲット": "es6"、
「experimentalDecorators」:true、
"preserveConstEnums":true、
"suppressImplicitAnyIndexErrors":true、
"lib":["es2015"、 "es2016"]
}、
"含む": [
"./src/*"
]、
"除外":[
「node_modules」
]
}
index.js
関数displayData(){
var myMap = new Map();
myMap.set( "name"、 "xxxxxxxx");
}
jsファイルに変換するコマンド

tsc .src \ index.ts
エラー :
src/index.ts:4:21 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the lib`コンパイラオプションをes2015以降に。

4 var myMap = new Map();
~~~

エラーが1つ見つかりました。`

@ Praveer1981解決策は、文字通りエラーメッセージにあります。

私はこれと同じ問題に遭遇し、tsconfig.jsonがエラーメッセージの内容を正確に示しているため、混乱しました。 tsconfig.jsonをさらに変更しても、問題は修正されません。

tscにファイルパスを渡すと、 tsconfig.jsonは無視されると思います。 これが私に起こっていたことです。

tsc src/foo.ts #ライブラリ/ターゲットをアップグレードすることを示すコンパイラエラーが発生します
tsc #tsconfig.jsonがes2015以降のターゲットを指定していたため、正常に動作します

したがって、これを取得してtsconfig.jsonに問題がない場合は、カスタムパスをコンパイラに渡しているかどうかを再確認し、構成を無視する可能性があります。

こっちも一緒

node_modules / @ types / react / index.d.ts:377:23-エラーTS2583:名前'Set'が見つかりません。 ターゲットライブラリを変更する必要がありますか? libコンパイラオプションをes2015以降に変更してみてください。

interactions: Set<SchedulerInteraction>,

構成:

{
  "compilerOptions": {
    "target": "es5",
    "target: "es5", // <= doesn't help
    "lib": [
      "dom",
      "dom.iterable",
      "esnext",
      "es2015", // <= doesn't help
      "es6", // <= doesn't help
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "sourceMap": true,
    "baseUrl": "./",
    "jsx": "preserve"
  },
  "include": [
    "./**/*",
    "*.tsx"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

私が解析したファイルは次のようになります。

class Greeter {
  public greeting: string;
  constructor(msg: string) {
    this.greeting = msg;
  }
}

let g = new Greeter('hello');

export { Greeter };

ここでは、 targetlibes6と同じです。
@types/[email protected]をインストールすることで、これを修正することができました。

@brunobertoldi
はい、確認できます。 あなたの答えは問題を解決します。
ここhttps://github.com/DefinitelyTyped/DefinitelyTyped/issues/29172#issuecomment-527708175

@brunobertoldi 、これに加えて、これらのタイピングをインストールするために管理者権限でプロンプトを開く必要がありましたが、一度実行すると機能しました。

ちなみに、ありがとうございます。

追加の詳細をありがとう、@ thomasio101!

ここでは、 targetlibes6と同じです。
@types/[email protected]をインストールすることで、これを修正することができました。

かっこいい!

create-react-appの仕組みに従うことをお勧めします

compilerOptionsの内部

    ...
    "skipLibCheck": true,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
   ...

libの内容は完全にあなた次第です。

ここでは、 targetlibes6と同じです。
@types/[email protected]をインストールすることで、これを修正することができました。

問題を解決する

このページは役に立ちましたか?
0 / 5 - 0 評価