LoginSignup
1
0

【Eslint】 'xxx is not defined'エラーの原因

Last updated at Posted at 2023-08-22

はじめに

SAPfiori UI5の静的解析を目的にEslintを導入しました。
その際に発生した'xxx is not defined'のエラーについて、sap、jQueryを例に以下に記載します。
参考になれば幸いです。

エラー

①sap
image.png

Error: 'sap' is not defined.

②jQuery
image.png

Error: 'jQuery' is not defined.

原因と解決方法

原因

ESLintは実行環境にどのようなグローバル変数が存在するかを想定していません。
そのため、以下の方法で定義する必要があります。

①設定ファイル内でグローバル変数を定義
②ソースコード内でコメントを使用して定義

解決方法① 設定ファイル内でグローバル変数を定義する

image.png

.eslintrc.js
globals: { sap: true, jQuery: true}

解決方法② ソースコード内でコメントを使用して定義する

image.png

/*global sap, jQuery */

結果

エラーが解消されていることが確認できました。
sap
image.png
jQuery
image.png

参考

・Eslint
https://eslint.org/docs/latest/use/configure/language-options#specifying-environments
・SAP
https://help.sap.com/doc/saphelp_nw74/7.4.16/en-us/cc/fe35638f1d46e2bbcf06fa60ccc6ef/frameset.htm

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