Heroku 部署失败 - 无法导入 Sass 个文件

Heroku deployment failure - cannot import Sass files

我正在尝试使用 Heroku 进行部署,但在导入 sass 文件时遇到有关节点 sass 的错误。

这似乎是 node-sass 的常见问题,但我找不到导入 scss 文件导致问题的原因。我已经重新安装了 node-sass 但这没有帮助。

//package.json

{
  "name": "crown-clothing",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "firebase": "^6.3.5",
    "node-sass": "^4.12.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-redux": "^7.1.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.0.1",
    "react-stripe-checkout": "^2.6.3",
    "redux": "^4.0.4",
    "redux-logger": "^3.0.6",
    "redux-persist": "^5.10.0",
    "reselect": "^4.0.0"
  },
  "scripts": {
    "start": "BROWSER=firefox react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "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"
    ]
  }
}


//错误信息

    Creating an optimized production build...
remote:        Failed to compile.
remote:        
remote:        ./src/components/directory/directory.styles.scss
remote:        To import Sass files, you first need to install node-sass.
remote:        Run `npm install node-sass` or `yarn add node-sass` inside your workspace.
remote:        
remote:        
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! crown-clothing@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR! 
remote: npm ERR! Failed at the crown-clothing@0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote: 
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.7gDk8/_logs/2019-08-26T17_18_16_441Z-debug.log
remote: 
remote: -----> Build failed
remote:        
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:        
remote:        Some possible problems:
remote:        
remote:        - Node version not specified in package.json
remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:        
remote:        Love,
remote:        Heroku

如您所见,导致问题的原因是导入 sass 个文件。

奇怪的是,我所要做的就是删除我的节点模块文件夹,重新安装节点-sass,然后在推送到 heroku 之前推送到 github。我不能说它们都是必要的,但它正在工作,并且不必转换和 css 文件类型。

因此,在尝试了多种操作(例如清除 Heroku 缓存、重新安装节点模型和重新部署但似乎无效)之后,我采取了以下步骤:

  • 将我所有的 .css 文件更改为 .sass 文件。

  • 安装 node-sass(我已经有了),然后将我的 git 存储库更新到最新版本的应用程序。成功了!