来自 UglifyJs 的 renderer.js 中的错误 Unexpected token punc «(» [英] ERROR in renderer.js from UglifyJs Unexpected token punc «(»

查看:33
本文介绍了来自 UglifyJs 的 renderer.js 中的错误 Unexpected token punc «(»的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

版本:webpack 2.3.3

Version: webpack 2.3.3

你好

我正在尝试使用 Vuejs 构建我的第一个 Electron 应用程序.在我来打包应用之前,一切似乎都很顺利.

I'm trying to build my first Electron app using Vuejs. Everything seems to be going great until I've come to package the app.

当我运行 npm run dev 时,一切正常.

When I run npm run dev everything works just fine.

但是,当我运行 npm build:darwin 时,出现以下错误

However, when I run npm build:darwin I get the following error

ERROR in renderer.js from UglifyJs意外的标记 punc «(», 预期的 punc «:» [renderer.js:26813,14]

它最终会编译,但是当我运行应用程序时,我得到了死机的白屏.

It does end up compiling however when I run the application I get the white screen of death.

据我所知,这可能是因为 Uglifyjs 不编译 ES6,但您可以通过 .babelrc 文件中的以下内容来克服这个问题

From what I read, this can be because Uglifyjs doesn't compile ES6 but you can overcome that by the following in your .babelrc file

"renderer": {
  "presets": [
    ["es2015", { "modules": false }],
    "stage-0"
  ]
}

我不知道如何调试.任何帮助将不胜感激.

I have no idea how to debug this. Any help would be greatly appreciated.

谢谢

生成的debug.log是...

The debug.log that is generated is...

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/7.9.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'pack' ]
2 info using npm@4.2.0
3 info using node@v7.9.0
4 verbose run-script [ 'prepack', 'pack', 'postpack' ]
5 info lifecycle FormBuff@0.0.0~prepack: FormBuff@0.0.0
6 silly lifecycle FormBuff@0.0.0~prepack: no script for prepack, continuing
7 info lifecycle FormBuff@0.0.0~pack: FormBuff@0.0.0
8 verbose lifecycle FormBuff@0.0.0~pack: unsafe-perm in lifecycle true
9 verbose lifecycle FormBuff@0.0.0~pack: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/admin/Code/electron/formbuff/node_modules/.bin:/Users/admin/Code/electron/formbuff/node_modules/.bin:/Users/admin/.config/yarn/link/node_modules/.bin:/Users/admin/Code/electron/formbuff/node_modules/.bin:/Users/admin/.config/yarn/link/    node_modules/.bin:/usr/local/Cellar/yarn/0.23.2/libexec/bin/node-gyp-bin:/Users/admin/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/admin/.composer/vendor/bin:/Users/admin/go/bin
10 verbose lifecycle FormBuff@0.0.0~pack: CWD: /Users/admin/Code/electron/formbuff
11 silly lifecycle FormBuff@0.0.0~pack: Args: [ '-c', 'npm run pack:main && npm run pack:renderer' ]
12 silly lifecycle FormBuff@0.0.0~pack: Returned: code: 2  signal: null
13 info lifecycle FormBuff@0.0.0~pack: Failed to exec pack script
14 verbose stack Error: FormBuff@0.0.0 pack: `npm run pack:main && npm run pack:renderer`
14 verbose stack Exit status 2
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:194:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:194:7)
14 verbose stack     at maybeClose (internal/child_process.js:899:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid FormBuff@0.0.0
16 verbose cwd /Users/admin/Code/electron/formbuff
17 error Darwin 16.5.0
18 error argv "/usr/local/Cellar/node/7.9.0/bin/node" "/usr/local/bin/npm" "run" "pack"
19 error node v7.9.0
20 error npm  v4.2.0
21 error code ELIFECYCLE
22 error errno 2
23 error FormBuff@0.0.0 pack: `npm run pack:main && npm run pack:renderer`
23 error Exit status 2
24 error Failed at the FormBuff@0.0.0 pack script 'npm run pack:main && npm run pack:renderer'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the FormBuff package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     npm run pack:main && npm run pack:renderer
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs FormBuff
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls FormBuff
24 error There is likely additional logging output above.
25 verbose exit [ 2, true ]

推荐答案

可以尝试安装这个版本的uglify,它叫做uglify-es,它是:

You can try to install this version of uglify, it called uglify-es and it is:

用于 ES6+ 的 JavaScript 解析器、编辑器/压缩器和美化工具包

JavaScript parser, mangler/compressor and beautifier toolkit for ES6+

uglify-es npm 链接

就我而言,我已经安装了 babel 插件来处理这个问题.如果你想尝试,你应该这样做:

In my case, I have installed babel plugin to handle this issue. If you want to try you should do this:

将此添加到您的 package.json

"babel-core": "latest",
"babel-loader": "latest",
"babel-plugin-transform-async-to-generator": "latest",
"babel-plugin-transform-runtime": "latest",
"babel-preset-es2015": "latest",
"babel-runtime": "latest"

将您的 webpack.config 文件设置为类似(例如我的):

Set you webpack.config file to be like (This is mine for example):

const path = require('path')
const webpack = require('webpack')

module.exports = {
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        publicPath: '/dist/',
        filename: 'build.js'
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.(png|jpg|gif|svg)$/,
                loader: 'file-loader',
                query: {
                    name: '[name].[ext]?[hash]'
                }
            },
            {
                test: /\.scss$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            }
        ]
    }
}

if (process.env.NODE_ENV === 'production') {
    module.exports.devtool = '#source-map'
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.optimize.UglifyJsPlugin({ sourceMap: true, compress: { warnings: false }})
    ])
}

将您的 .babelrc 文件设置为:

Set your .babelrc file to be like:

{
    "presets": ["es2015"],
    "plugins": ["transform-runtime", "transform-async-to-generator"]
}

希望有帮助:)

这篇关于来自 UglifyJs 的 renderer.js 中的错误 Unexpected token punc &amp;#171;(&amp;#187;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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