Я работаю над проектом React JS, где я использовал ActionHero в качестве сервера.На локальном хосте все работает нормально, но когда я пытался построить проект локально, я получаю это сообщение об ошибке.
vishal@vishal-pc:~/projects/x1-platform$ yarn run build
yarn run v1.12.3
warning package.json: No license field
warning ../../package.json: No license field
$ next build
> Using external babel configuration
> Location: "/home/vishal/projects/x1-platform/.babelrc"
> Using "webpack" config function defined in next.config.js.
> Failed to build on /tmp/c7a64326-b0fb-42d4-8537-3e83712fee01
{ Error: commons.js from UglifyJs
Unexpected token: punc ()) [commons.js:83270,22]
at /home/ampcome/projects/x1-platform/node_modules/next/dist/server/build/index.js:183:21
at emitRecords.err (/home/ampcome/projects/x1-platform/node_modules/webpack/lib/Compiler.js:269:13)
at Compiler.emitRecords (/home/ampcome/projects/x1-platform/node_modules/webpack/lib/Compiler.js:375:38)
at emitAssets.err (/home/ampcome/projects/x1-platform/node_modules/webpack/lib/Compiler.js:262:10)
at applyPluginsAsyncSeries1.err (/home/ampcome/projects/x1-platform/node_modules/webpack/lib/Compiler.js:368:12)
at next (/home/ampcome/projects/x1-platform/node_modules/tapable/lib/Tapable.js:218:11)
at Compiler.compiler.plugin (/home/ampcome/projects/x1-platform/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
at Compiler.applyPluginsAsyncSeries1 (/home/ampcome/projects/x1-platform/node_modules/tapable/lib/Tapable.js:222:13)
at Compiler.afterEmit (/home/ampcome/projects/x1-platform/node_modules/webpack/lib/Compiler.js:365:9)
at require.forEach.err (/home/ampcome/projects/x1-platform/node_modules/webpack/lib/Compiler.js:354:15)
at /home/ampcome/projects/x1-platform/node_modules/async/dist/async.js:473:16
at iteratorCallback (/home/ampcome/projects/x1-platform/node_modules/async/dist/async.js:1064:13)
at /home/ampcome/projects/x1-platform/node_modules/async/dist/async.js:969:16
at /home/ampcome/projects/x1-platform/node_modules/graceful-fs/graceful-fs.js:45:10
at FSReqWrap.oncomplete (fs.js:141:20)
errors:
[ 'commons.js from UglifyJs\nUnexpected token: punc ()) [commons.js:83270,22]' ],
warnings: [] }
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
next.config.js file
const path = require('path');
const merge = require('lodash.merge');
const glob = require('glob')
const Uglify = require('uglifyjs-webpack-plugin');
module.exports = {
webpack: (config) => {
config.resolve = merge({}, config.resolve, {
alias: {
Components: path.resolve(__dirname, 'components'),
Libs: path.resolve(__dirname, 'libs'),
Sagas: path.resolve(__dirname, 'sagas'),
},
});
config.module.rules.push(
{
test: /\.(css|scss)/,
loader: 'emit-file-loader',
options: {
name: 'dist/[path][name].[ext]'
}
}
,
{
test: /\.css$/,
use: ['babel-loader', 'raw-loader', 'postcss-loader']
}
,
{
test: /\.css$/,
loaders: [
'style-loader',
'css-loader'
]
},
{
test: /\.s(a|c)ss$/,
use: ['babel-loader', 'raw-loader', 'postcss-loader',
{ loader: 'sass-loader',
options: {
includePaths: ['scss', 'node_modules','styles']
.map((d) => path.join(__dirname, d))
.map((g) => glob.sync(g))
.reduce((a, c) => a.concat(c), [])
}
}
]
}
)
config.node = {
fs: 'empty',
};
return config;
},
};
В StackOverflow есть много решений для этой проблемы, но ни одно из них не работает для меня.
Я попытался деактивировать плагин Uglify, но он тоже не работает.