简体   繁体   English

React JS 导入 css 文件有表达式 no-unused-expressions

[英]React JS import css file had expression no-unused-expressions

In my React JS app add import a CSS file in component在我的 React JS 应用程序中,在组件中添加导入 CSS 文件
import("./assets/Base.scss");
When run npm start show this error in command prompt运行npm start在命令提示符中显示此错误

Line 17:1: Expected an assignment or function call and instead saw an expression no-unused-expressions

Line 17:1 is import("./assets/Base.scss");第 17:1 行是import("./assets/Base.scss");

I don't want to import css file like below我不想导入如下 css 文件
import './assets/Base.scss';
I want to import with parenthesis .我想用括号导入。

I had some rules for .eslintrc.js :我对.eslintrc.js有一些规则:

"use strict";

const fs = require("fs");
const path = require("path");

const restrictedPaths = [
  { name: "react-bootstrap" },
  { name: "@material-ui/core" }
].map(pkg =>
  fs
    .readdirSync(path.dirname(require.resolve(`${pkg.name}/package.json`)))
    .map(component => ({
      name: `${pkg.name}/${component}`,
      message: `This loads CommonJS version of the package. To fix replace with: import { ${component} } from "${pkg.name}";`
    }))
);

module.exports = {
  extends: "eslint-config-react-app",
  rules: {
    // "no-script-url": "warn",
    "jsx-a11y/anchor-is-valid": "warn",
    "no-restricted-imports": ["error", { paths: [].concat(...restrictedPaths) }]
  }
};

How can I solve this problem?我怎么解决这个问题?
Is the error displayed for rules in .eslintrc.js ? .eslintrc.js规则是否显示错误?

You need to write it like this:你需要这样写:

import "./assets/Base.scss";

Without the parenthesis没有括号

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

相关问题 在React中导入文件时,获得期望的赋值或函数调用,而是看到一个表达式no-unused-expressions - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions, when import a file in React 反应没有未使用的表达式 - React no-unused-expressions 没有未使用的表达式 React - no-unused-expressions React React 中的 no-unused-expressions - no-unused-expressions in React React JS - 错误 - 需要赋值或 function 调用,而是看到一个表达式 no-unused-expressions - React JS - Error - Expected an assignment or function call and instead saw an expression no-unused-expressions 反应中的 p5 js:期望赋值或函数调用,而是看到一个表达式 no-unused-expressions - p5 js in react : Expected an assignment or function call and instead saw an expression no-unused-expressions 期望一个赋值或 function 调用,而是看到一个表达式 no-unused-expressions - React Js Crud - Expected an assignment or function call and instead saw an expression no-unused-expressions - React Js Crud 没有未使用的表达式问题 React - No-unused-expressions issue React 带有条件的 React 中的 no-unused-expressions - no-unused-expressions in React with conditionals No-unused-expressions 错误在 React 中的脚本导入时不断出现 - No-unused-expressions error keeps recurring at script import in React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM