我在 Netlify 構建日志上收到此錯誤:
2:24:32 AM: error Generating JavaScript bundles failed
2:24:32 AM: Can't resolve '@layout/PageContainer' in '/opt/build/repo/src/pages/how-it-works'
2:24:32 AM: If you're trying to use a package make sure that '@layout/PageContainer' is installed. If you're trying to use a local file make sure that the path is correct.
2:24:32 AM: error Generating JavaScript bundles failed
2:24:32 AM: Can't resolve '@pages/HowItWorks' in '/opt/build/repo/src/pages/how-it-works'
2:24:32 AM: If you're trying to use a package make sure that '@pages/HowItWorks' is installed. If you're trying to use a local file make sure that the path is correct.
我已經設定了 webpack 別名,如下所示:
// gatsby-node.js
exports.onCreateWebpackConfig = ({ stage, actions }) => {
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, "src"), "node_modules"],
alias: {
"@pages": path.resolve(__dirname, "src/components/pages/"),
"@layout": path.resolve(__dirname, "src/components/layout/"),
},
extensions: [".js", ".json", ".jsx", ".tsx", ".ts"]
}
});
};
@pages 檔案結構如下: src -> components -> pages
@layout 檔案結構如下所示: src -> components -> layout
我可以在yarn build本地進行回購。沒有問題。
一旦我嘗試使用 Netlify 部署/構建,我就會遇到別名問題。為什么這不適用于 Netlify?
uj5u.com熱心網友回復:
我終于讓它作業了,但為什么它有效,我不知道!!
從我在這方面花費太多時間并嘗試 100 種不同的事情中發現的結果來看。Ubuntu檔案系統的行為與 Mac/Windows 非常不同,這就是為什么我能夠毫無問題地在本地構建(我使用的是 Windows)。Netlify只使用 Ubuntu 鏡像來構建,所以沒有使用其他東西的選項。
它類似于這里提到的內容:https : //github.com/gatsbyjs/gatsby/issues/2897
這是我為解決我的問題所做的:
Rename affected directories:
FROM:
src/components/layout
src/components/pages
TO:
src/components/Layout
src/components/Pages
And then I changed my alias's accordingly:
"@Pages": path.resolve(__dirname, "src/components/Pages")
"@Layout": path.resolve(__dirname, "src/components/Layout")
在此之后,我將我的更改提交給了 git 并在 Netlify 上運行了一個新版本......它就像魔法一樣奏效!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/400851.html
