首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >'TypeError: fs.existsSync不是一个函数‘React项目中发生的错误与'./node_modules/node-sass/lib/binding.js’有关。‘

'TypeError: fs.existsSync不是一个函数‘React项目中发生的错误与'./node_modules/node-sass/lib/binding.js’有关。‘
EN

Stack Overflow用户
提问于 2020-02-14 01:51:48
回答 5查看 2K关注 0票数 2

所以我已经尝试了一段时间了,现在我已经到了极限了。

我正在尝试创建一个react应用程序来进行简单的API调用,但是我一直收到这个错误,它阻止了我的lodable组件被呈现。

它作为我登录到chrome的console.log()的props.error出现。

在chrome的控制台中,我得到:

代码语言:javascript
复制
TypeError: fs.existsSync is not a function
at Object.hasBinary (extensions.js:404)
at module.exports (binding.js:11)
at Object.<anonymous> (index.js:14)
at Object../node_modules/node-sass/lib/index.js (index.js:471)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)
at Object../src/routes/app/routes/tacas/components/FeatureCallouts.js (lib sync:9)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)
at Object../src/routes/app/routes/tacas/components/template.js (styles.scss?8f6b:45)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)
at Object../src/routes/app/routes/tacas/index.js (index.js:1)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)

我认为这与'./node_modules/node-sass/lib/binding.js‘文件有关,该文件是:

代码语言:javascript
复制
/*!
 * node-sass: lib/binding.js
 */

var errors = require('./errors');

/**
 * Require binding
 */
module.exports = function(ext) {
  if (!ext.hasBinary(ext.getBinaryPath())) {
    if (!ext.isSupportedEnvironment()) {
      throw new Error(errors.unsupportedEnvironment());
    } else {
      throw new Error(errors.missingBinary());
    }
  }

  return require(ext.getBinaryPath());
};

同样在build CMD终端中,我也收到了这样的警告:

代码语言:javascript
复制
./node_modules/node-sass/lib/binding.js
19:9-37 Critical dependency: the request of a dependency is an expression

我看过其他类似的问题,但似乎都不适合我。例如,我根本没有webpack.config文件。

以防万一这里是我的package.json文件:

代码语言:javascript
复制
{
  "name": "material",
  "private": true,
  "version": "4.0.0",
  "main": "",
  "homepage": "",
  "scripts": {
    "start": "react-app-rewired start",
    "stop": "taskkill -F -IM node.exe",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test --env=jsdom",
    "eject": "react-scripts eject",
    "prettier": "prettier --write ./src/**/**/**/*"
  },
  "dependencies": {
    "@babel/runtime": "7.0.0-beta.55",
    "@material-ui/core": "^1.5.1",
    "@material-ui/icons": "^2.0.2",
    "@material-ui/lab": "^1.0.0-alpha.10",
    "axios": "^0.19.2",
    "classnames": "^2.2.6",
    "core-js": "^2.5.7",
    "date-fns": "2.0.0-alpha.7",
    "downshift": "^2.1.1",
    "echarts": "^4.1.0",
    "echarts-for-react": "^2.0.14",
    "element-resize-event": "^2.0.9",
    "font-awesome": "~4.7.0",
    "history": "^4.6.1",
    "jquery": "^3.4.1",
    "jquery-slimscroll": "~1.3.8",
    "material-ui-pickers": "1.0.0-rc.11",
    "prop-types": "^15.6.2",
    "rc-queue-anim": "^1.6.5",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-hot-loader": "^4.3.4",
    "react-loadable": "^5.5.0",
    "react-redux": "^5.0.7",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-router-redux": "5.0.0-alpha.6",
    "react-scripts": "2.0.0-next.3e165448",
    "redux": "^4.0.0",
    "redux-immutable-state-invariant": "^2.1.0",
    "redux-thunk": "^2.3.0"
  },
  "browserslist": {
    "development": [
      "last 2 chrome versions",
      "last 2 firefox versions",
      "last 2 edge versions"
    ],
    "production": [
      ">0.25%",
      "not op_mini all",
      "ie 11"
    ]
  },
  "devDependencies": {
    "bootstrap": "^4.4.1",
    "node-sass": "^4.13.1",
    "prettier": "^1.14.2",
    "react-app-rewire-provide-plugin": "^1.0.0",
    "react-app-rewired": "^1.5.2",
    "sass-loader": "^7.0.1"
  }
}

请帮帮忙,我是一名实习生,这是我得到的第一个项目,我不想把它搞砸。

EN

回答 5

Stack Overflow用户

发布于 2020-10-29 18:58:42

当我输入时,VS代码自动从node-sass导入TRUE,因此在文件中添加了import {TRUE} from 'node-sass',这导致了这个错误。移除它解决了问题。

票数 3
EN

Stack Overflow用户

发布于 2021-01-21 20:24:28

VS代码自动导入Null,就像@SadAzzi Answer一样,删除它对我来说一切都很有吸引力。

import { NULL } from "node-sass"

票数 2
EN

Stack Overflow用户

发布于 2020-02-14 09:56:33

Node-sass是一个原生C++模块,不能在浏览器中运行。有可能,但我从来没试过

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60213810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档