尝试将无服务器NextJS部署到AWS Lambda时出现Webpack问题

时间:2020-06-01 18:48:11

标签: amazon-web-services webpack aws-lambda next.js serverless

最近两天我一直在尝试,但似乎无法解决此问题。我发现了许多问题和教程,据说可以解决问题,但问题仍然存在。

这是我运行无服务器npx后的错误

    52s › nextApp › Error: Command failed with exit code 1: node_modules/.bin/next build
Failed to compile.

./images/blockchain-net.png 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

我找到了一个教程,说我需要实现url-loader和file-loader。我同时安装了两者,并尝试了多种不同的解决方案,但仍然收到此错误。这是我的next.config.js:

module.exports = withPlugins([
    [optimizedImages, {
        inlineImageLimit: 8192,
        imagesFolder: 'images',
        imagesName: '[name]-[hash].[ext]',
        handleImages: ['jpeg', 'jpg', 'png', 'svg', 'webp', 'gif', 'ico'],
        optimizeImages: true,
        optimizeImagesInDev: false,
        mozjpeg: {
            quality: 80,
        },
        optipng: {
            optimizationLevel: 3,
        },
        pngquant: false,
        gifsicle: {
            interlaced: true,
            optimizationLevel: 3,
        },
        webp: {
            preset: 'default',
            quality: 75,
        },
    }],
    [withCSS], [withFonts], [withSass], nextJsConfig,
]);

module.exports = withCSS(withSass({
    webpack(config, options) {
        config.module.rules.push({
            test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 100000
                }
            }
        })
        return config
    }
}));

module.exports = {
    target: 'serverless'
};

仅包含module.export节的部分。我被困住了,我不知道下一步该怎么做。当我运行npm run dev时,整个解决方案效果很好,但是现在,当我尝试运行无服务器时,这些错误就会显示出来。

0 个答案:

没有答案