无法修复“意外的令牌名称"i",预期的标点“;»";来自UglifyJs [英] Cannot fix "Unexpected token name «i», expected punc «;»" from UglifyJs

查看:345
本文介绍了无法修复“意外的令牌名称"i",预期的标点“;»";来自UglifyJs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了带有自定义下一个服务器的react应用

I have created a react app with a custom next server

server.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 问题,因为出现以下错误:

However, I have a problem with npm run build because I get the following error:

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引起的,所以我尝试通过以下链接来解决它:.我几乎尝试了所有建议,但没有一个奏效.

According to forums, the problem is caused because UglifyJs does not support ES6 so I tried to solve it with these links: this and this. I almost tried all the suggestion but none of them worked.

此外,我的根目录中没有webpack.config.js.因此,我在根目录中选择了以下内容(我不知道它是否正确): webpack.config.js:

Also, I did not have webpack.config.js in the root directory. So, I ceated one in the root(which I don't know whether it's correct or not) with this content: 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"
  }
}

有人可以帮我解决问题吗?

Can somebody help me solve the problem?

推荐答案

我通过完全删除节点模块文件夹解决了该问题.我一个接一个地安装了所有需要的模块,以找出哪个模块引起了问题.问题出在Next.js上.我安装了最新版本的Next.js,并通过在根目录中运行"npm install"来安装了其他所需的模块.

I resolved the problem by removing the node modules folder completely. I installed all needed modules one by one to find out which one is causing the problem. The problem was with Next.js; I installed the latest version of Next.js and by running "npm install" in root directory I installed other needed modules.

这篇关于无法修复“意外的令牌名称"i",预期的标点“;»";来自UglifyJs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆