1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

'変数名''datasets' is not defined とESlintに怒られる場合の対処法

Last updated at Posted at 2022-09-03

ESLintを挿入してReact でアプリケーションを作っている時の話。こんなエラーが出てずっと対処法に困っていた。
スクリーンショット 2022-09-03 21.32.32.png

Compiled with problems:X

ERROR

[eslint] 
src/App.tsx
  Line 17:5:   'datasets' is not defined     no-undef
  Line 18:9:   'label' is not defined        no-undef
  Line 19:9:   'data' is not defined         no-undef
  Line 20:9:   'borderColor' is not defined  no-undef
  Line 41:3:   'prefCode' is not defined     no-undef
  Line 42:3:   'prefName' is not defined     no-undef
  Line 67:60:  'NodeListOf' is not defined   no-undef

Search for the keywords to learn more about each error.

お世話になった記事(なっく日報さんから)

歴史的経緯により存在しているglobal変数を弾いてくれるための仕組みなんだそう。今回は必要ないのでエラーが出ないようにしたい。
.eslintrc.json ファイルを変更しglobalに値を記入するとエラーが消える仕組み。この事象の場合このように記載するとエラーが消える。

.eslintrc.json
{
	"env": {
		"browser": true,
		"es2021": true
	},
	"extends": ["eslint:recommended", "prettier"],
	"parserOptions": {
		"ecmaVersion": 12,
		"sourceType": "module"
	},
	"globals": {
		"datasets": false,
		"label": false,
		"data": false,
		"borderColor": false,
		"prefCode": false,
		"prefName": false,
		"NodeListOf": false,
		"Props": false,
		"labels": false
	},
	"rules": {
		"no-console": "off"
    }
}

そんじゃま!(´・ω・)ノシ

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?