umijs 提示 "'Globals' is not defined no-undef"

多次掉坑,记录下


环境

umi v2.13.13
node v12.16.1

问题

.umirc.local.js 或 .umirc.prod.js

define: {
    'Globals.API_HOST': '/api',
}

request.js

window.api_host = Globals.API_HOST;

启动或打包时报错:

 error  in ./src/utils/request.js

Module Error (from ./node_modules/eslint-loader/index.js):

  Line 9:19:  'Globals' is not defined  no-undef

原因1

打包命令未设置UMI_ENV,打包时未使用.umirc.prod.js

package.json

"build": "set UMI_ENV=prod&&umi build",

原因2

.env启用了ESLINT=1,删除即可

原因3(编译报错)

.eslintrc未设置globals

.eslintrc

{
  "extends": "eslint-config-umi",
  "globals": {
    "document": true,
    "localStorage": true,
    "window": true,
    "Globals": true
  },
  "parserOptions": {
    "ecmaFeatures": {
      "legacyDecorators": true
    }
  }
}
umiglobalstrueumi_enverrorapi_host