Я пытаюсь определить, вызвана ли указанная ниже проблема ошибкой в моих конфигурационных файлах или какой-то ошибкой в ESLint;и, наконец, как это исправить.
Версия ESLint : 5.9.0
Текст ошибки :
Module build failed (from ./node_modules/eslint-loader/index.js):
TypeError: Cannot read property 'range' of null
at Array.forEach (<anonymous>)
Причина ошибки :
В строке 117 из eslint/lib/rules/template-curly-spacing
вызывается функция с именем getFirstToken
.эта функция вызывает getOneToken
, который находится в строке 55 eslint/lib/token-store/forward-token-cursor.js
. Вот как выглядит эта функция:
getOneToken() {
return (this.index <= this.indexEnd) ? this.tokens[this.index] : null;
}
По некоторым причинам index
значение this
(ForwardTokenCursor) выходит за пределы диапазона this.indexEnd
, именно так ForwardTokenCursor выглядит как раз перед тем, как eslint возвращает ошибку: {current: null, tokens: Array(1188), index: 1092, indexEnd: 1090 }
Как видите, функция getOneToken вернет ноль вgetTokenBefore позже, когда к предполагаемому свойству этого нулевого объекта обращаются, это приводит к ошибке linter.Почему это может происходить?Я предполагаю, что это проблема с тем, как я настроил eslint, хотя я не знаю, почему это вызвало бы такую ошибку.Несмотря на это, я включил информацию о своей конфигурации здесь.
webpack.config.dev.js:
'use strict';
const autoprefixer = require('autoprefixer');
const path = require('path');
const paths = require('../paths');
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.config.common.js');
const InterpolateHtmlPlugin = require('../../scripts/create_react_app_utils/InterpolateHtmlPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const getClientEnvironment = require('../env');
const fs = require('fs');
// process.env.API_ENV = 'mock';
const env = getClientEnvironment('');
module.exports = merge(common, {
entry: [
require.resolve('../../scripts/create_react_app_utils/webpackHotDevClient'),
require.resolve('../polyfills'),
/* require.resolve('react-error-overlay'), */
paths.appIndexJs
],
output: {
pathinfo: true,
filename: 'static/js/bundle.js',
chunkFilename: 'static/js/main-react.chunk.js',
publicPath: '/',
devtoolModuleFilenameTemplate: info =>
path.resolve(info.absoluteResourcePath),
},
mode: 'development',
devtool: 'inline-source-map',
module: {
strictExportPresence: true,
rules: [
{
test: /\.(js|jsx)$/,
enforce: 'pre',
use: [
{
options: {
formatter: eslintFormatter,
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
},
{
exclude: [
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.json$/,
/\.bmp$/,
/\.gif$/,
/\.jpe?g$/,
/\.png$/,
/\.scss$/,
],
loader: require.resolve('file-loader'),
options: {
name: 'static/media/[name].[hash:8].[ext]',
},
},
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
sourceMap: true
},
},
{
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
],
},
{
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
},
{
loader: "css-loader", // translates CSS into CommonJS
options: {
sourceMap: true,
}
},
{
loader: "sass-loader", // compiles Sass to CSS
options: {
sourceMap: true,
data: '@import "globals";',
includePaths: [path.resolve(paths.appSrc, "./styles")]
}
}]
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
}),
new webpack.DefinePlugin(env.stringified),
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
new CaseSensitivePathsPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// new BundleAnalyzerPlugin()
]
});
.eslintrc
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"es6": true,
"jest": true
},
"globals": {
"React":true
},
"plugins": [
"react"
],
"extends": "airbnb",
"rules": {
"max-len": 0,
"one-var": 0,
"no-console": ["error", { "allow": ["warn", "error"] }],
"no-mixed-operators": 0,
"no-multiple-empty-lines": ["error", {"max": 2}],
"no-prototype-builtins": 0,
"class-methods-use-this": 0,
"padded-blocks": 0,
"no-return-assign": 0,
"no-unused-expressions": ["error", { "allowTernary": true }],
"camelcase": 0,
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"prefer-destructuring": ["off"],
"no-tabs": 0,
"no-mixed-spaces-and-tabs": "error",
"indent": ["error", "tab", { "SwitchCase": 1 }],
"new-cap": 0,
"spaced-comment": ["error", "always", { "exceptions": ["*"] }],
"import/no-named-as-default": 0,
"import/no-unresolved": 0, // Linting will not interpret aliases if this rule is turned on
"import/no-extraneous-dependencies": 0,
"import/extensions": 0,
"jsx-a11y/href-no-hash": 0,
"jsx-a11y/no-static-element-interactions": 0,
"jsx-a11y/no-noninteractive-element-interactions": 0, //Allow us to put event handlers on any HTML element
"jsx-a11y/no-noninteractive-tabindex": 0,
"react/forbid-prop-types": [2, { "forbid": ["any"] }],
"react/jsx-indent": [2, "tab"],
"react/jsx-indent-props": ["error", "tab"],
"react/jsx-filename-extension": 0,
"react/jsx-no-bind": 1,
"react/prefer-stateless-function": [1, { "ignorePureComponents": true }],
"react/sort-comp": 0
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"modules": true
}
}
}
Дайте мне знать в комментариях, еслилюбые другие файлы конфигурации или сборки необходимы.Я ценю вашу помощь, я нашел пару билетов с ошибками на eslint github, которые, кажется, связаны с этой проблемой, но они были закрыты и, казалось бы, не решены.https://github.com/eslint/eslint/issues/9872