我已经创建了一个带有自定义Next服务器的React应用程序。
server.js文件内容如下:
根据论坛的说法,该问题是由于UglifyJs不支持ES6而引起的,因此我尝试使用以下链接解决它:这个和这个。我几乎尝试了所有建议,但都没有奏效。
另外,我在根目录下没有webpack.config.js文件。因此,我在根目录下创建了一个(我不知道是否正确),其内容如下: webpack.config.js:
const { createServer } = require('http');
const next = require('next');
const app = next({
dev: process.env.NODE_ENV !== 'production',
conf: {
webpack: config => {
config.devtool = false;
for (const r of config.module.rules) {
if (r.loader === 'babel-loader') {
r.options.sourceMaps = false;
}
}
return config;
}
}
});
const routes = require('./routes');
const handler = routes.getRequestHandler(app);
app.prepare().then(() => {
createServer(handler).listen(3000, err => {
if (err) throw err;
});
});
然而,我在执行npm run build时遇到了问题,因为我收到了以下的错误信息:
Unexpected token name «i», expected punc «;» [commons.js:124406,11]
at /home/parstoo/Dropbox/Projects/Ethereum/SupplyChain/node_modules/next/dist/server/build/index.js:182:21
根据论坛的说法,该问题是由于UglifyJs不支持ES6而引起的,因此我尝试使用以下链接解决它:这个和这个。我几乎尝试了所有建议,但都没有奏效。
另外,我在根目录下没有webpack.config.js文件。因此,我在根目录下创建了一个(我不知道是否正确),其内容如下: webpack.config.js:
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
optimization: {
minimizer: [new UglifyJsPlugin()],
},
};
package.json 内容:
{
"name": "supplychain",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha",
"dev": "node server.js",
"start": "NODE_ENV=production server.js",
"transpile": "babel src -d dist --copy-files",
"prepublishOnly": "npm run transpile",
"build": "next build",
"deploy": "gh-pages -d examples/dist",
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/polyfill": "^7.2.5",
"fs-extra": "^7.0.1",
"ganache-cli": "^6.4.1",
"mocha": "^5.2.0",
"next": "^4.1.1",
"next-routes": "^1.4.2",
"radium": "^0.25.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"semantic-ui-react": "^0.82.5",
"solc": "^0.4.25",
"truffle-hdwallet-provider": "0.0.3",
"web3": "^1.0.0-beta.35"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^2.1.0",
"html-webpack-plugin": "^3.2.0",
"npm-install-webpack-plugin": "^4.0.5",
"terser-webpack-plugin": "^1.3.0",
"uglifyjs-webpack-plugin": "v1.0.0-beta.1",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.4",
"webpack-dev-server": "^3.7.2"
}
}
有人能帮我解决这个问题吗?