Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Cannot read property 'range' of null #681

Closed

Description

@ldwqh0

In my index.js

export module1  from './module1'
export module2 from './module2'

with the error

Cannot read property 'range' of null

and I use Decorator before export like this

@Decorator
export default Class A {
 ...
}

the error

Parsing error: Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead.

How do I solve these two problems?

Activity

  1. craigbeck commented on Sep 4, 2018

    @craigbeck
    $ npx eslint .
    Cannot read property 'range' of null
    (node:44758) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "node_modules/eslint-config-airbnb-base/index.js")
    
    > eslint . --cache --cache-file eslint-cache/eslintcache
    
    Cannot read property 'range' of null
    TypeError: Cannot read property 'range' of null
        at SourceCode.getTokenBefore (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/token-store/index.js:303:18)
        at checkSpacingBefore (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/rules/template-curly-spacing.js:52:42)
        at TemplateElement (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/rules/template-curly-spacing.js:117:17)
        at listeners.(anonymous function).forEach.listener (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/util/safe-emitter.js:45:58)
        at Array.forEach (<anonymous>)
        at Object.emit (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/util/safe-emitter.js:45:38)
        at NodeEventGenerator.applySelector (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/util/node-event-generator.js:251:26)
        at NodeEventGenerator.applySelectors (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/util/node-event-generator.js:280:22)
        at NodeEventGenerator.enterNode (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/util/node-event-generator.js:294:14)
        at CodePathAnalyzer.enterNode (/Users/craigbeck/dev/premise-frontend-v3/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)
    

    Also seeing similar error although we don't use decorators

  2. dsizomin commented on Sep 7, 2018

    @dsizomin

    Experiencing similar issue here.

    TypeError: Cannot read property 'range' of null
        at OffsetStorage.setDesiredOffset (/Users/dsizomin/Projects/RateFamily/frontend/node_modules/eslint/lib/rules/indent.js:335:45)
        at TemplateLiteral.node.expressions.forEach (/Users/dsizomin/Projects/RateFamily/frontend/node_modules/eslint/lib/rules/indent.js:1341:29)
        at Array.forEach (<anonymous>)
        at Object.TemplateLiteral [as listener] (/Users/dsizomin/Projects/RateFamily/frontend/node_modules/eslint/lib/rules/indent.js:1333:34)
        at Program:exit.listenerCallQueue.filter.forEach.nodeInfo (/Users/dsizomin/Projects/RateFamily/frontend/node_modules/eslint/lib/rules/indent.js:1529:55)
        at Array.forEach (<anonymous>)
        at Program:exit (/Users/dsizomin/Projects/RateFamily/frontend/node_modules/eslint/lib/rules/indent.js:1529:26)
        at listeners.(anonymous function).forEach.listener (/Users/dsizomin/Projects/RateFamily/frontend/node_modules/eslint/lib/util/safe-emitter.js:45:58)
        at Array.forEach (<anonymous>)
        at Object.emit (/Users/dsizomin/Projects/RateFamily/frontend/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    

    For me the troublesome lines are the ones containing template literals. Commenting out those makes eslint work.

  3. krousseau-cs commented on Sep 10, 2018

    @krousseau-cs

    I have the same issue. I'm not going to remove all template literals just for this upgrade since everything seems to still work with 8.2.6.

  4. ZackKnopp commented on Sep 12, 2018

    @ZackKnopp

    See: #530
    What worked for me in .eslintrc:

    // TODO: Remove when is https://github.com/babel/babel-eslint/issues/530 fixed
      rules : {
        "template-curly-spacing" : "off",
        indent : "off"
      }
    
  5. ljqx commented on Oct 16, 2018

    @ljqx

    I encountered similar problem, finally I found that it's because of existence of 2 @babel/types.

    babel-eslint changes data in @babel/types and assumes @babel/traverse would consume it. But as npm/yarn may create different @babel/types to avoid conflict, the change on @babel/types may not take affect on @babel/traverse.

    So

    - node_modules
      - @babel
        - traverse
        - types
      - babel-eslint
    

    Would work. But

    - node_modules
      - @babel
        - traverse
          - node_modules
            - @babel
              - types
      - babel-eslint
        - node_modules
          - @babel
            - types
    

    won't work.

    @hzoo , I think here it's better to pass in the @babel/types instead of implicitly depending on same dependency which may not be true.

  6. ldwqh0 commented on Oct 16, 2018

    @ldwqh0
    Author

    I have resolved this

    Parsing error: Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead.

    add this config in my .eslintrc.js file

      parserOptions: {
        ecmaFeatures: {
          legacyDecorators: true
        },
        parser: 'babel-eslint'
      }

    but the "Cannot read property 'range' of null" error can not be resolved
    wait online

  7. joepvl commented on Jan 4, 2019

    @joepvl

    FWIW, I'm getting the same error, with eslint 5.11.1 and npm 6.5.0. Switching to yarn fixes it, so from that perspective it seems like a dependency/determinicness issue. However, I want to keep using npm, and I also don't want to downgrade.

    In my case at least the error is generated during handling of template literals within the indent rule. I can live with not checking indentation for template literals, so I've fixed it for now using the ignoredNodes option for the indent rule, roughly as follows:

    "indent": ["error", 2, {
      "ignoredNodes": ["TemplateLiteral"]
    }]

    Not sure how else I can be of help, except maybe reiterate @ljqx's suggestion of trying to normalize the @babel/types dep across babel and babel-eslint. I can't tell if npm is doing something wrong here or if yarn's more deterministic algorithm is hiding a flaw in the code.

  8. aarongeorge commented on Jan 14, 2019

    @aarongeorge

    I was having this issue myself using:

    • eslint v5.12.0
    • babel-eslint v10.0.1.

    Using the following code words:

    const foo = 'bar';
    console.log('We\'re going for drinks at the ' + foo);
    

    However if I change it to use a template literal with a placeholder:

    const foo = 'bar';
    console.log(`We're going for drinks at the ${foo}`);
    

    I get the error: Cannot read property 'range' of null.

    It seems to be an issue with using template literals that contain a placeholder as using:

    console.log(`We're going for drinks at the bar`);
    

    I upgraded babel-eslint's package.json to the following and it fixes the issue:

    {
      "name": "babel-eslint",
      "version": "10.0.1",
      "description": "Custom parser for ESLint",
      "main": "lib/index.js",
      "files": [
        "lib"
      ],
      "repository": {
        "type": "git",
        "url": "https://github.com/babel/babel-eslint.git"
      },
      "dependencies": {
        "@babel/code-frame": "^7.0.0",
        "@babel/parser": "^7.0.0",
        "@babel/traverse": "^7.0.0",
        "@babel/types": "^7.0.0",
        "eslint-scope": "4.0.0",
        "eslint-visitor-keys": "^1.0.0"
      },
      "scripts": {
        "test": "npm run lint && npm run test-only",
        "test-only": "mocha && mocha --require test/fixtures/preprocess-to-patch.js",
        "lint": "eslint lib test",
        "fix": "eslint lib test --fix",
        "precommit": "lint-staged",
        "preversion": "npm test",
        "changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'"
      },
      "author": "Sebastian McKenzie <sebmck@gmail.com>",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      },
      "bugs": {
        "url": "https://github.com/babel/babel-eslint/issues"
      },
      "homepage": "https://github.com/babel/babel-eslint",
      "peerDependencies": {
        "eslint": ">= 4.12.1"
      },
      "devDependencies": {
        "babel-eslint": "^10.0.1",
        "dedent": "^0.7.0",
        "eslint": "^5.6.0",
        "eslint-config-babel": "^8.0.2",
        "eslint-plugin-flowtype": "^3.2.1",
        "eslint-plugin-import": "^2.14.0",
        "eslint-plugin-prettier": "^3.0.1",
        "espree": "^5.0.0",
        "husky": "^1.0.0-rc.13",
        "lint-staged": "^8.1.0",
        "mocha": "^5.0.1",
        "prettier": "^1.4.4"
      },
      "lint-staged": {
        "*.js": [
          "eslint --format=codeframe --fix",
          "git add"
        ]
      }
    }
    

    Also @hzoo is there any reason as to why babel-eslint has babel-eslint as a devDependency?

  9. lizuncong commented on Jan 14, 2019

    @lizuncong

    I have the same issue. I'm not going to remove all template literals just for this upgrade since everything seems to still work with 8.2.6.
    Have you resolved this question

  10. ldwqh0 commented on Jan 14, 2019

    @ldwqh0
    Author

    It looks like this problem has been resolved !

    I changed this .babelrc to babel.config.js in my project
    package.json

    {
      "name": "element-seed",
      "version": "1.3.1",
      "description": "A Vue.js project",
      "author": "ldwqh0 <ldwqh0@outlook.com>",
      "private": true,
      "scripts": {
        "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
        "start": "npm run dev",
        "lint": "eslint --ext .js,.vue src",
        "build": "node build/build.js",
        "ts-compile": "tsc",
        "fix": "eslint --fix --ext .js,.vue src"
      },
      "dependencies": {
        "@babel/polyfill": "^7.0.0",
        "animate.css": "^3.7.0",
        "animejs": "^2.2.0",
        "axios": "^0.18.0",
        "echarts": "^4.2.0-rc.2",
        "echarts-wordcloud": "^1.1.3",
        "element-datatables": "^0.2.3",
        "element-ui": "^2.4.7",
        "lodash": "^4.17.11",
        "qrcodejs2": "^0.0.2",
        "qs": "^6.5.1",
        "resize-detector": "^0.1.9",
        "vue": "^2.5.20",
        "vue-property-decorator": "^7.1.0",
        "vue-router": "^3.0.1",
        "vue2-uploader": "0.1.8",
        "vuex": "^3.0.1",
        "vuex-class": "^0.3.0",
        "wangeditor": "^3.1.1"
      },
      "devDependencies": {
        "@babel/core": "^7.2.0",
        "@babel/plugin-proposal-class-properties": "^7.2.1",
        "@babel/plugin-proposal-decorators": "^7.2.0",
        "@babel/plugin-proposal-do-expressions": "^7.2.0",
        "@babel/plugin-proposal-export-default-from": "^7.2.0",
        "@babel/plugin-proposal-export-namespace-from": "^7.2.0",
        "@babel/plugin-proposal-function-sent": "^7.2.0",
        "@babel/plugin-proposal-json-strings": "^7.2.0",
        "@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
        "@babel/plugin-proposal-nullish-coalescing-operator": "^7.2.0",
        "@babel/plugin-proposal-numeric-separator": "^7.2.0",
        "@babel/plugin-proposal-object-rest-spread": "^7.2.0",
        "@babel/plugin-proposal-optional-chaining": "^7.2.0",
        "@babel/plugin-proposal-pipeline-operator": "^7.2.0",
        "@babel/plugin-proposal-throw-expressions": "^7.2.0",
        "@babel/plugin-syntax-dynamic-import": "^7.2.0",
        "@babel/plugin-syntax-import-meta": "^7.2.0",
        "@babel/plugin-syntax-jsx": "^7.2.0",
        "@babel/plugin-transform-runtime": "^7.2.0",
        "@babel/preset-env": "^7.2.0",
        "@babel/runtime": "^7.2.0",
        "@types/node": "^10.12.12",
        "ajv": "^6.6.1",
        "autoprefixer": "^9.4.2",
        "babel-eslint": "^10.0.0",
        "babel-loader": "^8.0.4",
        "babel-plugin-component": "^1.1.1",
        "chalk": "^2.0.1",
        "copy-webpack-plugin": "^4.5.1",
        "css-loader": "^2.0.0",
        "eslint": "^5.10.0",
        "eslint-config-standard": "^12.0.0",
        "eslint-friendly-formatter": "^4.0.0",
        "eslint-loader": "^2.1.1",
        "eslint-plugin-html": "^5.0.0",
        "eslint-plugin-import": "^2.7.0",
        "eslint-plugin-node": "^8.0.0",
        "eslint-plugin-promise": "^4.0.0",
        "eslint-plugin-standard": "^4.0.0",
        "eslint-plugin-vue": "^5.0.0",
        "file-loader": "^3.0.0",
        "friendly-errors-webpack-plugin": "^1.6.0",
        "html-webpack-plugin": "^3.1.0",
        "less": "^3.8.0",
        "less-loader": "^4.1.0",
        "mini-css-extract-plugin": "^0.5.0",
        "mockjs": "^1.0.1-beta3",
        "node-notifier": "^5.1.0",
        "node-xlsx": "^0.12.1",
        "optimize-css-assets-webpack-plugin": "^5.0.0",
        "ora": "^3.0.0",
        "portfinder": "^1.0.20",
        "postcss-import": "^12.0.0",
        "postcss-loader": "^3.0.0",
        "postcss-url": "^8.0.0",
        "rimraf": "^2.6.0",
        "semver": "^5.3.0",
        "shelljs": "^0.8.0",
        "ts-node": "^7.0.1",
        "typescript": "^3.2.1",
        "uglifyjs-webpack-plugin": "^2.0.1",
        "url-loader": "^1.0.0",
        "vue-loader": "^15.4.0",
        "vue-style-loader": "^4.1.0",
        "vue-template-compiler": "^2.5.20",
        "webpack": "^4.27.1",
        "webpack-bundle-analyzer": "^3.0.2",
        "webpack-cli": "^3.1.1",
        "webpack-dev-server": "^3.1.0",
        "webpack-merge": "^4.1.0"
      },
      "engines": {
        "node": ">= 6.0.0",
        "npm": ">= 3.0.0"
      },
      "browserslist": [
        "> 1%",
        "last 2 versions",
        "not ie <= 8"
      ]
    }

    babel.config.js

    module.exports = function (api) {
      api.cache(true)
      return {
        presets: [
          [
            '@babel/preset-env',
            {
              'modules': false,
              'targets': {
                'browsers': [
                  '> 1%',
                  'last 2 versions',
                  'not ie <= 8'
                ]
              },
              'useBuiltIns': 'entry'
            }
          ]
        ],
        plugins: [
          [
            'component',
            {
              'libraryName': 'element-ui',
              'styleLibraryName': 'theme-chalk'
            }
          ],
          // 在babel转码的时候,有些语法会转换为一些特殊函数,这个插件提供了这些公共函数,用以解决打包之后的体积
          '@babel/plugin-transform-runtime',
          // 这个插件编译@import('')语法
          '@babel/plugin-syntax-dynamic-import',
          // 处理对象的解构语法,即{...a}模式
          [
            '@babel/plugin-proposal-object-rest-spread',
            {
              'loose': true
            }
          ],
          // 处理decorators语法
          [
            '@babel/plugin-proposal-decorators',
            {
              // export写在@decorators的前面
              // @decorator
              // export class Foo {}
              // 否则就是 export @decorator class Bar {} 这种模式
              // 'decoratorsBeforeExport': true,
    
              // 必须设置legacy为true,不然vue报错,编译能通过,但会发生运行时错误,提示组件属性无效
              // 项目使用了vue-property-decorator模式导致的
              'legacy': true
            }
          ],
          // 处理类的属性语法
          [
            '@babel/plugin-proposal-class-properties',
            {
              // 使用哪种方式定义对象的属性,如果loose为true,使用
              // var Bork = function Bork() {
              //   babelHelpers.classCallCheck(this, Bork);
              //   this.x = 'bar';
              //   this.y = void 0;
              // };
              // 的模式增加属性,
              // 否则使用Object.defineProperty的模式附加属性
              // 项目使用了vue-property-decorator模式,必须使用loose模式
              'loose': true
            }
          ],
          // 处理 export module from 'xxx'语法
          '@babel/plugin-proposal-export-default-from',
          // 处理 export * as ns from 'mod' 语法
          '@babel/plugin-proposal-export-namespace-from',
          // 处理带分隔符的数字
          '@babel/plugin-proposal-numeric-separator'
        ]
      }
    }

    There is no error in my project when use export module from '../file'
    this is my test project

  11. l443018 commented on Jan 18, 2019

    @l443018

    @ldwqh0 could you attach complete error log in output channel?

    In my case, I encountered similar log as @dsizomin
    I solved it by remove yarn.lock, node_modules and run yarn install again (need to restart VS code): #530 (comment)

    [Error - 11:55:33 AM] TypeError: Cannot read property 'range' of null
        at OffsetStorage.setDesiredOffset (/home/laura/Documents/project/kid-guard-api/node_modules/eslint/lib/rules/indent.js:335:45)
        at TemplateLiteral.node.expressions.forEach (/home/laura/Documents/project/kid-guard-api/node_modules/eslint/lib/rules/indent.js:1335:29)
        at Array.forEach (<anonymous>)
        at Object.TemplateLiteral [as listener] (/home/laura/Documents/project/kid-guard-api/node_modules/eslint/lib/rules/indent.js:1327:34)
        at Program:exit.listenerCallQueue.filter.forEach.nodeInfo (/home/laura/Documents/project/kid-guard-api/node_modules/eslint/lib/rules/indent.js:1537:55)
        at Array.forEach (<anonymous>)
        at Program:exit (/home/laura/Documents/project/kid-guard-api/node_modules/eslint/lib/rules/indent.js:1537:26)
        at listeners.(anonymous function).forEach.listener (/home/laura/Documents/project/kid-guard-api/node_modules/eslint/lib/util/safe-emitter.js:45:58)
        at Array.forEach (<anonymous>)
        at Object.emit (/home/laura/Documents/project/kid-guard-api/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    
  12. dallashall-procore commented on Feb 15, 2019

    @dallashall-procore

    This problem popped up for me after running npm audit fix to clear some npm vulnerability warnings, which bumped my version of eslint from v5.8.0 to v5.13.0

    Removing my package-lock.json and node_modules folder and running npm install worked to resolve this in my case.

    eslint: v5.13.0
    babel-eslint: v10.0.1

  13. aramk commented on May 17, 2019

    @aramk

    I fixed this issue by making sure I only have the one version of @babel/types:

    npm list @babel/types
    

    I targeted version 7.3.4 and some packages were using the newer 7.4.4. For those packages I reverted to an older version which used @babel/types@7.3.4. I did this without adding the dependency to package.json. An npm install is sufficient to update the package-lock.json.

    Then I ran the dedupe command to ensure I had no duplicates of @babel/types, since having multiple copies of the same version will still cause issues.

    npm dedupe @babel/types
    

    You should then see that the npm list command shows a single @babel/types without "dedupe" and all others with it, indicating they're references. After this the linter ran just fine.

  14. minhna commented on Jun 25, 2019

    @minhna

    Removing my package-lock.json and node_modules folder and running npm install worked to resolve this in my case.

    It works. Thank you.

  15. 30 remaining items

  16. mhdcodes commented on May 3, 2020

    @mhdcodes

    For any one reading this, here is how I solved this issue :
    I added the following snippet to my .eslintrc under the rules directive :

      "rules": {
        "template-curly-spacing": "off",
        "indent": [
          "warn",
          2,
          {
            "ignoredNodes": ["TemplateLiteral"],
            "SwitchCase": 1
          }
        ]
    }
  17. lolmaus commented on May 3, 2020

    @lolmaus

    Tried @elhaouari-mohammed 's suggestion. Unfortunately, did not help me.

    My error happens at build time, so ESLint does not seem to be involved.

  18. mhdcodes commented on May 3, 2020

    @mhdcodes

    @lolmaus Actually for me it's the gitlab pipelines that fails because of eslint, everything works on local environment and on deploy server, so it's really weird , as @NicholasIoanJones said : Appeared out of nowhere.

  19. lolmaus commented on May 3, 2020

    @lolmaus

    I've noticed that the error message has changed for me.

    Instead of Cannot read property 'range' of null it's now saying Debug failure.

  20. lolmaus commented on May 4, 2020

    @lolmaus

    Both error messages are very generic.

    Multiple unrelated issues might lead to them.

  21. agm1984 commented on May 5, 2020

    @agm1984

    I started reproducing this earlier today while pasting code into my project. It seemed like ES Lint got overwhelmed by hundreds of infractions.

    At the moment, I am seeing this:

    [Info  - 10:31:45 PM] Cannot read property 'range' of null Occurred while linting .../resources/js/router/routes.js:2
    [Info  - 10:31:46 PM] Cannot read property 'range' of null Occurred while linting .../resources/js/router/routes.js:2
    [Info  - 10:31:47 PM] Cannot read property 'range' of null Occurred while linting .../resources/js/router/routes.js:2
    

    That piece of code is:

    function page (path) {
        return () => import(/* webpackChunkName: '' */ `/resources/js/pages/${path}`).then(m => m.default || m);
    }

    Simply commenting out the import keyword fixes it.

    I tried wrapping the problematic block with /* eslint-disable */ and /* eslint-enable */, but the dynamic import keyword's appearance breaks the engine.

    I changed the code to concatenation:

    function page(path) {
        return () => import(/* webpackChunkName: '' */ '/resources/js/pages/' + path).then(m => m.default || m); // eslint-disable-line prefer-template
    }

    I've never seen this error before from "just template literals", so if I had anything to contribute, it would be that the import keyword is related. When I remove that keyword but keep the template literal, it un-breaks ES Lint.

  22. packetstracer commented on May 17, 2020

    @packetstracer

    i'm using CRA (react-scripts@3.4.1), yarn and react-app-rewired@2.1.6 and this issue happens to me only transpiling the tests (yarn test) with import sentences using template literals such as this one:

    import(`${path}`)

    Neither of the commented solutions worked for me but using the patch of disabling the corresponding eslint rules. To me this is not a valid solution, but by the moment will use it.

    See: #530
    What worked for me in .eslintrc:

    // TODO: Remove when is https://github.com/babel/babel-eslint/issues/530 fixed
      rules : {
        "template-curly-spacing" : "off",
        indent : "off"
      }
    

    This solution worked for me. Thanks!

  23. cdll commented on Jun 1, 2020

    @cdll

    same issue here with "babel-eslint": "^10.0.1" in @vue/cli.

  24. paschalidi commented on Jun 1, 2020

    @paschalidi

    adding to the package.json would solve the issue for me

    {
        "resolutions": {
            "@babel/parser": "7.7.5"
        }
    }
    

    Also run

    git clean -fdx 
    

    to clean all history of npm modules in your project and then reinstall them using

    npm i or yarn
    
  25. KrishnaPG commented on Jul 1, 2020

    @KrishnaPG

    Facing the same problem with below code:

    return import(/* webpackChunkName: "lang-[request]" */ `./lang/${lang}`)
    

    Following the @richardvanbergen suggestion above, removed the template string and instead used as below and the warning went away.

    return import(/* webpackChunkName: "lang-[request]" */ "./lang/"+lang)
    

    Hope to see this fixed soon.

  26. romulof commented on Jul 1, 2020

    @romulof

    @ljqx:

    I encountered similar problem, finally I found that it's because of existence of 2 @babel/types.

    babel-eslint changes data in @babel/types and assumes @babel/traverse would consume it. But as npm/yarn may create different @babel/types to avoid conflict, the change on @babel/types may not take affect on @babel/traverse.

    So

    - node_modules
      - @babel
        - traverse
        - types
      - babel-eslint
    

    Would work. But

    - node_modules
      - @babel
        - traverse
          - node_modules
            - @babel
              - types
      - babel-eslint
        - node_modules
          - @babel
            - types
    

    won't work.

    @hzoo , I think here it's better to pass in the @babel/types instead of implicitly depending on same dependency which may not be true.

    I'm getting this error with template-curly-spacing and indent rules with this node_modules layout:

    • @babel
      • traverse@7.10.1
        • node_modules
          • debug (non related, i guess)
          • msty (non related, i guess)
      • types@7.10.1
        • node_modules
    • babel-eslint@10.1.0
      • node_modules

    Adjusting both rules like this works:

    "rules": {
        "indent": ["error", 4, { "ignoredNodes": ["TemplateLiteral"] }],
        "template-curly-spacing" : "off"
    }

    @aramk:

    I fixed this issue by making sure I only have the one version of @babel/types:

    npm list @babel/types
    

    I targeted version 7.3.4 and some packages were using the newer 7.4.4. For those packages I reverted to an older version which used @babel/types@7.3.4. I did this without adding the dependency to package.json. An npm install is sufficient to update the package-lock.json.

    Then I ran the dedupe command to ensure I had no duplicates of @babel/types, since having multiple copies of the same version will still cause issues.

    npm dedupe @babel/types
    

    You should then see that the npm list command shows a single @babel/types without "dedupe" and all others with it, indicating they're references. After this the linter ran just fine.

    I have just a single version of @babel/types:

    $ npm list @babel/types
    project /path/to/project
    ├─┬ @babel/core@7.10.1
    │ ├─┬ @babel/generator@7.10.1
    │ │ └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/helper-module-transforms@7.10.1
    │ │ ├─┬ @babel/helper-replace-supers@7.10.1
    │ │ │ ├─┬ @babel/helper-member-expression-to-functions@7.10.1
    │ │ │ │ └── @babel/types@7.10.1  deduped
    │ │ │ └── @babel/types@7.10.1  deduped
    │ │ ├─┬ @babel/helper-simple-access@7.10.1
    │ │ │ └── @babel/types@7.10.1  deduped
    │ │ ├─┬ @babel/helper-split-export-declaration@7.10.1
    │ │ │ └── @babel/types@7.10.1  deduped
    │ │ └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/helpers@7.10.1
    │ │ └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/template@7.10.1
    │ │ └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/traverse@7.10.1
    │ │ ├─┬ @babel/helper-function-name@7.10.1
    │ │ │ └── @babel/types@7.10.1  deduped
    │ │ └── @babel/types@7.10.1  deduped
    │ └── @babel/types@7.10.1 
    ├─┬ @babel/plugin-transform-runtime@7.10.1
    │ └─┬ @babel/helper-module-imports@7.10.1
    │   └── @babel/types@7.10.1  deduped
    ├─┬ @babel/preset-env@7.10.1
    │ ├─┬ @babel/plugin-proposal-async-generator-functions@7.10.1
    │ │ └─┬ @babel/helper-remap-async-to-generator@7.10.1
    │ │   ├─┬ @babel/helper-wrap-function@7.10.1
    │ │   │ └── @babel/types@7.10.1  deduped
    │ │   └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/plugin-transform-classes@7.10.1
    │ │ ├─┬ @babel/helper-annotate-as-pure@7.10.1
    │ │ │ └── @babel/types@7.10.1  deduped
    │ │ ├─┬ @babel/helper-define-map@7.10.1
    │ │ │ └── @babel/types@7.10.1  deduped
    │ │ └─┬ @babel/helper-optimise-call-expression@7.10.1
    │ │   └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/plugin-transform-exponentiation-operator@7.10.1
    │ │ └─┬ @babel/helper-builder-binary-assignment-operator-visitor@7.10.1
    │ │   ├─┬ @babel/helper-explode-assignable-expression@7.10.1
    │ │   │ └── @babel/types@7.10.1  deduped
    │ │   └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/plugin-transform-modules-systemjs@7.10.1
    │ │ └─┬ @babel/helper-hoist-variables@7.10.1
    │ │   └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/plugin-transform-parameters@7.10.1
    │ │ └─┬ @babel/helper-get-function-arity@7.10.1
    │ │   └── @babel/types@7.10.1  deduped
    │ ├─┬ @babel/preset-modules@0.1.3
    │ │ └── @babel/types@7.10.1  deduped
    │ └── @babel/types@7.10.1  deduped
    ├─┬ babel-eslint@10.1.0
    │ └── @babel/types@7.10.1  deduped
    ├─┬ babel-jest@25.4.0
    │ └─┬ @types/babel__core@7.1.7
    │   ├── @babel/types@7.10.1  deduped
    │   ├─┬ @types/babel__generator@7.6.1
    │   │ └── @babel/types@7.10.1  deduped
    │   ├─┬ @types/babel__template@7.0.2
    │   │ └── @babel/types@7.10.1  deduped
    │   └─┬ @types/babel__traverse@7.0.11
    │     └── @babel/types@7.10.1  deduped
    └─┬ jest@25.4.0
      └─┬ @jest/core@25.4.0
        └─┬ jest-snapshot@25.4.0
          └── @babel/types@7.10.1  deduped
    
  27. Powersource commented on Jul 16, 2020

    @Powersource

    I believe (although not sure) I started getting this when updating from babel-eslint 10.0.3 to 10.1.0

  28. added a commit that references this issue on Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions