Async await – Babel eslint: typeerror: cannot read null property ‘range’

I use Babel eslint to decorate / fix my code It worked well until I wanted to use some es2017 async waiting to find over here

I changed my react application accordingly, although there are some differences:

My index Relevant parts of JS:

async function renderApp() {
  const store = await configureStore()

  const history = syncHistoryWithStore(browserHistory,store,{
    selectLocationState: state => state.get('routing')
  })

  ReactDOM.render(
    <AppContainer>
      <MuiThemeProvider muiTheme={muiTheme}>
        <Provider store={store}>
          <Router history={history} routes={routes(store)} />
        </Provider>
      </MuiThemeProvider>
    </AppContainer>,document.getElementById('root')
  )
}


renderApp()

My store:

// @flow

import 'babel-polyfill'

import { addFormSubmitSagaTo } from 'redux-form-submit-saga/es/immutable'
import { applyMiddleware,createStore,compose } from 'redux'
import { autoRehydrate,persistStore } from 'redux-persist-immutable'
import { browserHistory } from 'react-router'
import { combineReducers } from 'redux-immutable'
import { fromJS } from 'immutable'
import { routerMiddleware } from 'react-router-redux'
import createSagaMiddleware from 'redux-saga'

import rootReducer from './rootReducer'
import sagas from './rootSaga'

export default function configureStore() {
  return new Promise((resolve,reject) => {
    try {
      const sagaMiddleware = createSagaMiddleware()
      const middleware = [ routerMiddleware(browserHistory),sagaMiddleware ]

      const enhancer = compose(
        autoRehydrate(),applyMiddleware(...middleware)
      )
      const store = createStore(
        combineReducers(rootReducer),undefined,enhancer
      )

      // Decorate with Redux Form Submit Saga
      // and create hook for saga's
      const rootSaga = addFormSubmitSagaTo(sagas)
      sagaMiddleware.run(rootSaga)

      // Persist store to the local storage
      persistStore(
        store,{ whitelist: ['auth','timezone'] },() => resolve(store)
      )
    } catch (e) {
      reject(e)
    }
  })
}

This is mine. eslintrc:

{
  "env": {
    "browser": true,"jest/globals": true
  },"extends": [
    "standard","standard-flow","plugin:react/recommended"
  ],"plugins": [
    "compat","jest","react"
  ],"parserOptions": {
    "ecmaVersion": 2017,"sourceType": "module","ecmaFeatures": {
      "jsx": true
    }
  },"rules": {
    "comma-dangle": ["warn","only-multiline"],"compat/compat": 2,"jest/no-disabled-tests": "warn","jest/no-focused-tests": "error","jest/no-identical-title": "error","max-len": ["warn",80],"no-debugger": 0,"react/jsx-uses-vars": [2]
  }
}

This is mine. babelrc:

{
  "plugins": [
    "react-hot-loader/babel","Syntax-flow","tcomb","transform-class-properties"
  ],"presets": [
    "es2015","react",["env",{
      "targets": {
        "browsers": ["last 2 versions"]
      }
    }]
  ]
}

But no matter what I do: I keep getting the following errors:

Module build Failed: TypeError: Cannot read property 'range' of null
    at TokenStore.getTokenBefore (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/token-store/index.js:318:17)
    at EventEmitter.checkFunction (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/rules/generator-star-spacing.js:131:42)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:191:7)
    at NodeEventGenerator.enterNode (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/util/node-event-generator.js:39:22)
    at CodePathAnalyzer.enterNode (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Controller.enter (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/eslint.js:928:36)
    at Controller.__execute (/Users/danielterwiel/dev/nimbus/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/Users/danielterwiel/dev/nimbus/node_modules/estraverse/estraverse.js:501:28)
 @ multi react-hot-loader/patch webpack-hot-middleware/client babel-polyfill ./src/index.js ./src/style/main.css

I'm not quite sure what to do I have encountered similar problems in multiple posts, but until now, these have not been answered

Solution

Previously, eslint supported es2017 asynchronous / wait itself. Babel and eslint were listed in Babel- eslint@7.0.0. Workarounds that were removed you should upgrade to V7 all day - eslint or, if you can't do this, use eslint plug-in - Babel's patched generator star spacing rule

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>