简体   繁体   English

将样式导入React组件时,Eslint Babel抑制错误

[英]Eslint babel suppress error when importing styles into react component

I'm using es6 react and I import my styles into a component with: 我正在使用es6 react,并将样式导入到具有以下内容的组件中:

import styles from './MyStyle.sass';

I'm linting with eslint with these npm modules: 我通过以下npm模块来支持eslint:

"babel-eslint": "^6.1.2",
"eslint": "^3.16.0",
"eslint-plugin-react": "^6.10.0",

and here's my (a bit long) .eslintrc.yml file: 这是我的.eslintrc.yml文件(有点长):

---
  extends:
    - plugin:react/recommended

  env:
    browser: true
    node: true
    es6: true

  parserOptions:
   ecmaVersion: 6
   sourceType: "module"
   ecmaFeatures:
    jsx: true

  globals:
    __DEV__: true
    __SERVER__: true

  plugins:
    - react

  parser: "babel-eslint"
  rules:
    react/jsx-uses-vars: 1
    react/prop-types: [1, { ignore: [children] }]

    semi: 0
    key-spacing: 1
    curly: 0
    consistent-return: 0
    space-infix-ops: 1
    camelcase: 0
    no-spaced-func: 1
    no-alert: 1
    eol-last: 1
    comma-spacing: 1
    eqeqeq: 1

    # possible errors
    comma-dangle: 0
    no-cond-assign: 2
    no-console: 0
    no-constant-condition: 2
    no-control-regex: 2
    no-debugger: 2
    no-dupe-args: 2
    no-dupe-keys: 2
    no-duplicate-case: 2
    no-empty-character-class: 2
    no-empty: 2
    no-ex-assign: 2
    no-extra-boolean-cast: 2
    no-extra-parens: 0
    no-extra-semi: 2
    no-func-assign: 2
    no-inner-declarations: 2
    no-invalid-regexp: 2
    no-irregular-whitespace: 2
    no-negated-in-lhs: 2
    no-obj-calls: 2
    no-regex-spaces: 2
    no-sparse-arrays: 2
    no-unexpected-multiline: 2
    no-unreachable: 2
    use-isnan: 2
    valid-jsdoc: 2
    valid-typeof: 2

    no-redeclare: 2

    init-declarations: 2
    no-catch-shadow: 2
    no-delete-var: 2
    no-label-var: 2
    no-shadow-restricted-names: 2
    no-shadow: 2
    no-undef-init: 2
    no-undef: 2
    no-undefined: 2
    no-unused-vars: 2
    no-use-before-define: 2

The problem is that eslint complain that "Default export is not declared in imported modules" regarding the imported styles module. 问题是,eslint抱怨有关导入的styles模块“在导入的模块中未声明默认导出”。

Edit: 编辑:
1) The same question applies for imports such as 1)同样的问题适用于诸如

import logo_img from './img/home_logo.png'

2) Of course I am using webpack and the style/sass/css/url/file loaders 2)当然我正在使用webpack和style / sass / css / url / file加载器

Question: 题:
How can I suppress this warning? 如何抑制此警告?

You can mask the warning by doing a batch import like so: 您可以通过批量导入来屏蔽警告,如下所示:

import * as styles from './MyStyle.sass';

You can also include regular node modules this way as well, as this error is quite common when importing those too. 您也可以以这种方式包括常规节点模块,因为导入这些模块时也很常见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 eslint在需要react组件时给出只读错误吗? - eslint is giving a read only error when requiring a react component? 导入React组件时出错 - Error In Importing react Component 汇总错误:导入 Material-UI 组件时无法从 @babel/runtime 加载模块 - Rollup error: could not load a module from @babel/runtime when importing a Material-UI component ESLint导入反应 - ESLint importing react 将样式导入到React组件中时,如何分配基于关闭状态进行更新的className? - When importing styles into a React component, how do I assign a className that updates based off state? React - 将 className 添加到 Link 组件,ESLint 错误 - React - adding className to Link component, ESLint error 当我在nextjs上使用babel别名时出现Eslint错误 - Eslint error when I use babel alias on nextjs 将模块导入新的 create-react-app 项目时,构建时出现 Babel/JSX Transpiler 错误 - Babel/JSX Transpiler error on build when importing a module into new create-react-app project 错误:无法加载在“.eslintrc”中声明的解析器“babel-eslint”:在 create-react-app 中找不到模块“babel-eslint” - Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint' in create-react-app 组件定义中的Babel语法错误起反应 - Babel Syntax error in component definition react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM