-
I’m starting to build out a new Next.js app (9.4.4) using a webpack config based an older app, but I’m getting this error when I try to build in serverless mode:
I’ve been doing some digging and I’m pretty sure the error message (originating here) is a red herring; inserting some Here is my full const path = require('path');
const webpack = require('webpack');
const withSass = require('@zeit/next-sass');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const cdnHost = process.env.CDN_HOST || '';
const environmentName = process.env.ENVIRONMENT_NAME || 'development';
module.exports = withSass({
target: 'serverless',
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName:
environmentName === 'development' ? '[folder]-[local]-[hash:8]' : '[folder]-[hash:16]',
},
sassLoaderOptions: {
includePaths: [path.resolve(__dirname, '../node_modules/@kapowaz')],
},
postcssLoaderOptions: {
parser: true,
autoprefixer: {
browsers: ['last 2 versions'],
},
config: {},
},
webpack: (config, options) => {
const { dev, isServer } = options;
const buildId = options.buildId ? options.buildId : 'dev';
const newConfig = config;
newConfig.module.rules.push({
test: /\.(ico|icns|png|jpg|jpeg|svg|gif|ttf|woff)$/,
use: [
{
loader: 'file-loader',
options: {
emitFile: !isServer,
name: '[name].[hash:8].[ext]',
publicPath: (url) => `${cdnHost}/_next/static/${url}`,
outputPath: 'static/',
},
},
],
});
newConfig.module.rules.push({
test: /\.css$/,
use: [
{
loader: 'css-loader',
},
],
});
newConfig.plugins.push(
new webpack.DefinePlugin({
'process.env.ENVIRONMENT_NAME': JSON.stringify(environmentName),
'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production'),
'process.env.CDN_HOST': JSON.stringify(cdnHost),
'process.env.BUILD_ID': JSON.stringify(buildId),
}),
new CleanWebpackPlugin(),
);
newConfig.resolve.alias = {
...config.resolve.alias,
};
return newConfig;
},
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
So, after a lengthy investigation I found the culprit — |
Beta Was this translation helpful? Give feedback.
So, after a lengthy investigation I found the culprit —
clean-webpack-plugin
was apparently the cause of theroutes-manifest.json
file being removed. Removing this from the webpack config fixed the issue!