I am trying to integrate ESLint with a Jenkinsfile, that is started with a dockerfile image. Whenever I run the build in Jenkins, I get the following error:
ESLint couldn't find the plugin "eslint-plugin-react".
Here are my docker and jenkins files (with some non-needed parts taken out...):
Dockerfile.node:
FROM node:14
RUN npm install -g eslint@latest --save-dev
RUN npm install -g react@17.0.1 --save-dev
RUN npm install -g react-app@1.1.2 --save-dev
RUN npm install -g eslint-plugin-react@7.26.1 --save-dev
RUN npm install -g typescript@4.3.4 --save-dev
RUN npm install -g @typescript-eslint/parser@5.0.0 --save-dev
RUN npm install -g @typescript-eslint/eslint-plugin@5.0.0 --save-dev
RUN useradd jenkins --shell /bin/bash --create-home
USER jenkins
Jenkinsfile stage (the .eslintrc file lives in the source/web-ui folder):
stage('Run ESLint') {
agent {
dockerfile {
filename 'Dockerfile.node'
dir 'docker/'
reuseNode true
}
}
post {
failure {
echo '-- ESLint Failed! -- Please fix the above warnings/errors.'
}
success {
echo 'ESLint succeeded!'
}
}
steps {
dir(path: 'source/web-ui') {
echo 'Running ESLint against JS and TSX files'
sh'''
eslint --config .eslintrc.json .. --ext .js,.tsx
'''
}
}
}
and finally, here is my .eslintrc file:
{
"env": {
"browser": true,
"node": true,
"es6": true
},
/* RECOMMENDED RULES extended from plugins.
If you need to remove one of the recommended rules, you may add it to the rules section (using "off" in array options),
which will override recommended rules. */
"extends": [
"eslint:recommended", // https://eslint.org/docs/rules/ - rules with ✓ are included
"plugin:react/recommended", // https://github.com/yannickcr/eslint-plugin-react
"plugin:@typescript-eslint/recommended" // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/README.md
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"overrides": [
{
//if javascript file, ignore these rules:
"files": ["*.{js,jsx}"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-this-alias" : "off",
"@typescript-eslint/no-unused-vars": "off"
}
}
],
"rules": {
},
"settings": {
"react": {
"version": "17.0.1"
}
}
}
It's tripping me up because it's finding eslint globally and running it, but hitting a wall when trynig to find the react plugin, which was installed at the same time eslint was. I tried adding the --resolve-plugins-relative-to flag on, but that came up with the same error. I'm fairly new to docker, so I'm guessing it's something in that file?