【问题标题】:ReferenceError: loader is not definedReferenceError:未定义加载程序
【发布时间】:2020-06-07 08:11:33
【问题描述】:

我一直在开发一个带有 nodejs 后端的 React 应用程序。现在,当我运行npm run build 时出现此错误。我已将 node 和 npm 更新到最新版本。我在控制台中收到以下错误日志。

$ npm run build

> client@0.1.0 build C:\Demos\mern-course\client
> react-scripts build

Creating an optimized production build...
Failed to compile.

./src/App.css
ReferenceError: loader is not defined

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我的package.json如下。

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "bootstrap": "^4.4.1",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-redux": "^7.2.0",
    "react-scripts": "^3.4.0",
    "react-transition-group": "^4.3.0",
    "reactstrap": "^8.4.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "uuid": "^3.4.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:5000",
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Here is the link for github repo for the code.

【问题讨论】:

  • 您添加的错误详细信息没有ReferenceError: loader is not defined 显示在哪里?
  • 请在终端/控制台中npm ERR! code ELIFECYCLE这一行上方提供更多实际错误。
  • @Chathura Devinda 请编辑您的问题。
  • 编译器显示错误在您的 app.css 文件中,您可以浏览文件并检查文件中的“加载器”
  • @AkhilAravind app.css 文件仅包含一些 css 样式。我已经替换了初始 creat-react-app 模板中的所有默认内容。

标签: node.js reactjs redux react-redux


【解决方案1】:
./src/App.css
ReferenceError: loader is not defined

您需要检查您是否正确导入了App.css。这应该在您的 App.js 中

【讨论】:

  • 谢谢@Afia。由于 App.css 和 App.js 处于同一级别,所以在 App.js 中导入不会出错。
  • 嗨@ChathuraDevinda,你能解决这个问题吗?如果没有,请尝试从 App.js 中删除 css 并再次尝试构建。但在此之前,请检查控制台是否有任何错误或警告消息。
  • 嗨@Afia 经过几次尝试后,我尝试创建一个新项目并且它成功了。所以我替换了 css-loader 文件夹并且它工作了!
【解决方案2】:

将前端节点模块文件夹中的“css-loader”文件夹替换为另一个从工作反应项目中获取的“css-loader”。

【讨论】:

    猜你喜欢
    • 2019-12-31
    • 1970-01-01
    • 2023-03-07
    • 2012-08-24
    • 2021-01-14
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 2021-06-04
    相关资源
    最近更新 更多