【发布时间】:2021-12-29 10:37:03
【问题描述】:
我在 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?
【问题讨论】:
标签: reactjs webpack gatsby alias netlify