[每当我尝试将Rails 6应用推到Heroku时,我总是收到错误消息“预编译资产失败”。我从追溯中注意到,它抱怨“ @ fortawesome / fontawesome-free / js / all”导入的“字段'浏览器'不包含有效的别名配置”。
Field 'browser' doesn't contain a valid alias configuration
remote: /tmp/build_7682b1717ca625690f7939609cc5a51d/app/javascript/@fortawesome/fontawesome-free/js/all doesn't exist
remote: .jsx
remote: Field 'browser' doesn't contain a valid alias configuration
remote: /tmp/build_7682b1717ca625690f7939609cc5a51d/app/javascript/@fortawesome/fontawesome-free/js/all.jsx doesn't exist
remote: .mjs
remote: Field 'browser' doesn't contain a valid alias configuration
remote: /tmp/build_7682b1717ca625690f7939609cc5a51d/app/javascript/@fortawesome/fontawesome-free/js/all.mjs doesn't exist
remote: .js
remote: Field 'browser' doesn't contain a valid alias configuration
remote: /tmp/build_7682b1717ca625690f7939609cc5a51d/app/javascript/@fortawesome/fontawesome-free/js/all.js doesn't exist
remote: .sass
remote: Field 'browser' doesn't contain a valid alias configuration
remote: /tmp/build_7682b1717ca625690f7939609cc5a51d/app/javascript/@fortawesome/fontawesome-free/js/all.sass doesn't exist
remote: .scss
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
[根据一些建议,我试图将项目中的FontAwesome导入从import "@fortawesome/fontawesome-free/js/all"
修改为```import”。/fortawesome / fontawesome-free / js / all,但这对我不起作用。
我必须检查我的package.json
文件,然后发现dependencies
列表中没有包含该字体超棒的软件包,但devDependencies
列表中未包括该字体,可能是因为我没有使用-dev
选项进行安装。这是我的字体package.json
文件,然后我将字体包移至dependencies
列表。
"dependencies": {
"@babel/preset-react": "^7.8.3",
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "4.2.2",
"bootstrap": "^4.4.1",
"jquery": "^3.5.0",
"popper.js": "^1.16.1",
"prop-types": "^15.7.2",
"toastr": "^2.1.4",
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"@fortawesome/fontawesome-free": "^5.13.0",
"webpack-dev-server": "^3.10.3"
}
将fontawesome程序包移动到dependencies
列表后,我能够将我的应用程序成功推送到Heroku。