Error on build production vue/vuetify program with vue-google-adsense: SyntaxError: Unexpected token: punc «(»
rts-gordon opened this issue · 6 comments
Hi everyone,
I installed vue-script2 and vue-google-adsense in my project, then "npm run build" to generate static files, I got such errors:
ERROR in Encountered an error while minifying static/js/vendor.00bf8bdf.js:
SyntaxError: Unexpected token: punc «(»
43045 |
43046 | // keys are the scripts that is loading or loaded, values are promises
43047 | install(Vue) {
| ^
43048 | if (Script2.installed) return;
43049 | var customAttrs = ['unload']; // from: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
43050 | // 'async' and 'defer' don't allow document.write according to:
The components version follows:
"vue": "^2.6.11",
"vuetify": "^1.5.24",
"vue-google-adsense": "^1.8.1",
"vue-script2": "^2.1.0",
What am I doing error? thank you very much.
Can you give me your webpack config?
Hi mazipan, thank you very much. There are some webpack configs, a bit long. I used a third party component "webpack-parallel-uglify-plugin", I think it may be cause this error.
const devWebpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: config.dev.devtool,
mode: 'development',
// these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /./, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
],
},
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay
? { warnings: false, errors: true }
: false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: config.dev.poll,
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': env
//'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.']
}
])
]
})
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port
portfinder.getPort((err, port) => {
if (err) {
reject(err)
} else {
// publish the new Port, necessary for e2e tests
process.env.PORT = port
// add port to devServer config
devWebpackConfig.devServer.port = port
// Add FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [Your application is running here: http://localhost:${port}
, Your application is running here: http://${get_ip()}:${port}
],
},
onErrors: config.dev.notifyOnErrors
? utils.createNotifierCallback()
: undefined
}))
resolve(devWebpackConfig)
}
})
})
Actually you doesn't need to compile or minify this module since I publish the minified version only.
You will get the minified version.
Process it via Babel or Uglify/Terser doesn't required.
I will try this. Thank you.
Let me know if you still stuck on this.
Just my opinion, use Terser is better to minify modern code rather than Uglify.
Yes, Terser is better than Uglify.
Vue-google-adsense is works on Nuxt framework, I have changed to Nuxt, so I don't stuck on this issue.
Thank you again.