开发者问题收集

ReferenceError:加载器未定义

2020-02-23
2756

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

$ npm run build

> [email protected] 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! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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"
    ]
  }
}

这是代码的 github repo 链接。

2个回答
./src/App.css
ReferenceError: loader is not defined

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

Afia
2020-02-23

将前端 node-modules 文件夹中的“css-loader”文件夹替换为从工作 react 项目中获取的另一个“css-loader”。

Avilon
2020-02-24