如何解决NextSJ Config中的Webpack-ModuleParseError:模块解析失败:意外字符
从nextjs应用程序构建或使用yarn dev命令启动服务器时出现错误。 这是next.config.js。直到我安装和卸载了next-less插件,它才能正常工作。 我将代码恢复为以前的状态,但错误未解决。
const nextConfig = {
env: {
HOST_URL: process.env.HOST_URL,BUILD_ENV: process.env.BUILD_ENV,},webpack: (config,{ isServer }) => {
if (isServer) {
const antStyles = /antd\/.*?\/style\/css.*?/;
const origExternals = [...config.externals];
// eslint-disable-next-line no-param-reassign
config.externals = [
// eslint-disable-line
(context,request,callback) => {
// eslint-disable-line
if (request.match(antStyles)) return callback();
if (typeof origExternals[0] === 'function') {
origExternals[0](context,callback);
} else {
callback();
}
return null;
},...(typeof origExternals[0] === 'function' ? [] : origExternals),];
config.module.rules.unshift({
test: antStyles,use: 'null-loader',});
}
return config;
},};
module.exports = withPlugins(
[
[withBundleAnalyzer,{}],[withImages],[withCss],[
withSass,{
cssModules: true,cssLoaderOptions: {
localIdentName: '[path]_[local]_[hash:base64:5]',],nextConfig,);
解决方法
我解决了这个问题。我删除了项目根目录中的yarn.lock文件,因此当yarn安装节点包时,也会安装一些独立版本的依赖项。 这会导致scss加载程序未正确安装,并且webpack出现错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。