Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why I am getting error no-named-as-default #425

Closed
sqal opened this issue Jul 7, 2016 · 14 comments
Closed

Why I am getting error no-named-as-default #425

sqal opened this issue Jul 7, 2016 · 14 comments

Comments

@sqal
Copy link

sqal commented Jul 7, 2016

Hi. I have some issue with the plugin and here's what is happening:

app/index.js

import Vue from 'vue';
import App from 'components/App' // <-- Error: import/no-named-as-default Parse errors in imported module 'components/App': Unexpected token < (1:1)at line 4 col 17 in src\app\index.js
...

components/App is .vue file, which looks like below:

<template>
  <div></div>
</template>

<script>
  export default {
    name: 'App',
  };
</script>

But when I import some default export from .js file there is no error like that, so this bug(?) seems to be related to files with .vue extension. Any idea how i can fix this? Thanks.

My config:

package.json

{
  ...
  "eslint": "^3.0.1",
  "eslint-config-airbnb-base": "^4.0.0",
  "eslint-import-resolver-webpack": "^0.3.2",
  "eslint-plugin-html": "^1.5.1",
  "eslint-plugin-import": "^1.9.2",
}

.eslintrc

{
  "extends": "airbnb-base",
  "plugins": [
    "html",
    "import"
  ],
  "settings": {
    "import/resolver": {
      "webpack": {
        "config": "webpack/webpack.config.base.js"
      }
    }
  },
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true
    }
  }
}
@benmosher
Copy link
Member

benmosher commented Jul 7, 2016

Looks like you need jsx:true in your parserOptions:

Sorry, did not fully digest your post. You should specify import/extensions to avoid parsing .vue files:

  "settings": {
    "import/extensions": [".js"],
    "import/resolver": {
      "webpack": {
        "config": "webpack/webpack.config.base.js"
      }
    }
  },

This will be the default in v2+.

@sqal
Copy link
Author

sqal commented Jul 7, 2016

@benmosher

Hmm that doesn't seem to fix the issue, because now i have other error:

import/no-named-as-default Parse errors in imported module 'components/App': Adjacent JSX elements must be wrapped in an enclosing tag (11:1)at line 4 col 17 in src\app\index.js

@benmosher
Copy link
Member

Yep, sorry, I jumped the gun on my initial response. Try the updated edit with import/extensions.

@sqal
Copy link
Author

sqal commented Jul 7, 2016

Now we are back to the original error :/

@benmosher
Copy link
Member

Strange. Can you provide the relative paths of the source, components/App, and your .eslintrc?

@benmosher
Copy link
Member

Would be helpful if you can confirm what import plugin version you have installed, too: npm ls | grep import

@sqal
Copy link
Author

sqal commented Jul 7, 2016

@benmosher https://github.com/sqal/eslint-import-bugs If you would take a look at this, i would very much appreciate it

btw. i checked verions of installed eslint plugins, and all matches with versions in package.json

@benmosher
Copy link
Member

It's worth noting that the Webpack resolver technically doesn't support Webpack 2 (yet: #265), though that doesn't seem to be the issue.

@benmosher benmosher added the bug label Jul 7, 2016
@sqal
Copy link
Author

sqal commented Jul 7, 2016

Yeah, i checked with webpack 1.x and errors are the same unfortunately

@sqal
Copy link
Author

sqal commented Sep 21, 2016

I think this can be closed now since I no longer have any errors after updating all dependencies to the latest version :)

@guidobouman
Copy link

@sqal How did you get it to check the imports on vue files?

@sqal
Copy link
Author

sqal commented Sep 29, 2016

@guidobouman

Here's my eslint config:

---
root: true
parser: babel-eslint
extends: airbnb-base
env:
  browser: true
plugins:
  - html
  - flowtype
parserOptions:
  ecmaFeatures:
    experimentalObjectRestSpread: true
rules:
  import/no-extraneous-dependencies:
    - error
    - devDependencies: true
  import/extensions:
    - error
    - always
    - js: never
      vue: never
  flowtype/define-flow-type: 1
  flowtype/use-flow-type: 1
settings:
  import/resolver:
    webpack:
      config: config/webpack.config.base.js

@guidobouman
Copy link

OMG! It works! Had to use the base config instead of the dev one, that one failed apparently.

@guidobouman
Copy link

Thanks @sqal !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants