unimported 升级导致应用 Build 出错

295 阅读1分钟

项目工程化中有使用 Unimported 对未使用的代码进行检测, image.png

  • 这一波版本更新后,项目 检测, build 失败,出现以下错误,经常发现 node 版本不匹配,之前使用 14 升级到 16 解决
 npx: installed 159 in 18.314s
 Unexpected token '??='
  • 另一个问题是类型的引入检查需要加 type 类型

相关 scripts

    "unimported:ci": "npx unimported",
    "lint:quiet": "eslint -c .eslintrc.js --ext .ts,.tsx src --quiet",
    "lint:fix": "eslint -c .eslintrc.js --ext .ts,.tsx src --fix",
    "prettier:format-codes": "prettier --write src",
    "prettier:check": "prettier --check src",
    "ci:run": "yarn prettier:check && yarn lint:quiet && yarn unimported:ci",
    "ci:fix": " yarn lint:fix && yarn unimported:ci && yarn prettier:format-codes",

shell 脚本

set -ex

# tar xf ***.tar.gz
cp -rT *** .

# show all files at current dir
echo  "show all files at current dir"
ls -al

export SASS_BINARY_SITE=https://registry.npmmirror.com/mirrors/node-sass

# export DISABLE_ESLINT_PLUGIN=true
yarn install 

if [[ "$VAN_GIT_BRANCH" == *"master"* || "$VAN_GIT_BRANCH" == *"release"* ]]; then
	echo "==== Branch: $VAN_GIT_BRANCH. It's master or release branch, won't run 'ci' command."
else 
	echo "==== Branch: $VAN_GIT_BRANCH. It's not master nor release branch, run 'ci' first. if this progress fails, run 'ci' on your local machine and fix all errors."
	yarn ci:run
fi

echo "==== Branch: $VAN_GIT_BRANCH, ci done or ignored. Go on 'yarn build'"

yarn build