关于npm run build 报错解决方案
# 特定的错误
ERROR in statics/mobile/js/vendor.cef13a0e680a5bc0d8b3.js from UglifyJs
Unexpected token: punc (() [D:/Users/Administrator/Desktop/WTFpolice/newPolice/~/mint-ui/src/utils/clickoutside.js:12,0][statics/mobile/js/vendor.cef13a0e680a5bc0d8b3.js:43784,6]
经过一顿 stackoverflow之后 发现这么几点问题
1.没有配置babel
2.UglifyJs插件不支持es6
我针对这些答案都尝试了一遍最后得出如下方案
问题1的解决
如果是没有配置babel 也是有可能的因为如果你在chrome下开发不装babel 也是可以跑得顺畅的因为chrome对es6的支持是很好的
# 安装babel 的依赖
npm install babel-loader babel-core babel-preset-env babel-preset-stage-2 -D
以上依次是babel的转换器,核心库,预处理和预处理的es6版本
然后需要在根目录建立一个.babelrc的文件 配置如下
{
"presets": [
["env",
{
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
],
}
但很多情况下我们都是配置了,那么我们来看问题2
如果是UglifyJs插件不支持处理es6 官网有对应支持es6的版本,不过我们不是为了压缩es6
修改webpack.base.conf配置
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
# 修改前
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
}
# 修改后
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'),resolve('node_modules/mint-ui/scr/utils')]
}
如果你选择更新UglifyJs插件可以配合安装babel-polyfill , babel-polyfill可以模拟ES6使用的环境,可以使用ES6的所有新方法
# 安装
npm install -save babel-polyfill
# 修改在webpack.config.js配置
# 修改前
module.exports = {
entry: {
app: "./src/main.js"
}
}; # 修改后
module.exports = {
entry: {
app: ["babel-polyfill", "./src/main.js"]
}
};
关于npm run build 报错解决方案的更多相关文章
- vue-electron 使用sqlite3数据库,执行npm run build 报错 .NET Framework 2.0 SDK,Microsoft Visual Studio 2005[C:\temp\wechat\node_modules\sqlite3\build\binding.sln]
问题描述 vue-electron 使用sqlite3数据库,执行npm run build 报错如下: .NET Framework 2.0 SDK,Microsoft Visual Studio ...
- vue中执行npm run build报错解决方法?
遇到了执行npm run build 后报错: [build:js ] Module not found: Error: Can't resolve 'scss-loader' in 'D:\work ...
- npm run build报错(npm ERR! code ELIFECYCLE)的解决办法
具体报错如下图: 环境:centos7 应该node_modules安装问题,我们需要重新安装 rm -rf node_modules rm package-lock.json npm cache c ...
- 转载:TypeError: Cannot read property 'compilation' of undefined vue 打包运行npm run build 报错
转载自:https://www.jianshu.com/p/3f8f60e01797 运行npm run build打包时,报错如下: 我的package.json如下: { ... " ...
- vue.js环境配置步骤及npm run dev报错解决方案
安装完成后,使用npm run dev 运行,成功后,就可以在浏览器中看到vue的欢迎画面了 最后一步可能报错,我就遇到这样的问题了, 个人问题仅供参考: ERROR Failed to compil ...
- npm run build报错 ,resolve is not defined
今天在build项目的时候报: ReferenceError: resolve is not defined npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ...
- vue2.x 在引用插件的时候,npm run dev跑正常 ,npm run build 报错vue-cli Unexpected token: punc (() [
这是因为,引用的插件在node_modules里,并不在vue-cli的es6编译范围内,所以语法报错,修改方法:
- npm run build 报错 Error: No PostCSS Config found in...
module.exports = { plugins: [ require('autoprefixer')//自动添加css前缀 ] }; 在项目根目录新建postcss.config.js文件,添加 ...
- npm run build报错 No PostCSS Config found in
在项目根目录新建postcss.config.js文件,并对postcss进行配置: module.exports = { plugins: [ require('autoprefixer')//自动 ...
随机推荐
- docker实践3
我的docker学习笔记3 $docker run ubuntu echo'hello world' $docker run -i -t ubuntu /bin/bash #ps -ef #exi ...
- WebService(1-1)webservice调用
参考url : http://www.cnblogs.com/flying607/p/6254045.html 今天用动态创建客户端的方式调用webservice,报了这样一个错: 2017-01-0 ...
- maven管理的jsp应用如何添加servlet、jsp相关依赖(org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp)
背景: 老大让做权限控制,研究了一下shiro,下了个demo下来,死活跑不起来,报 org.apache.jasper.JasperException: java.lang.ClassNotFoun ...
- Spring整合MyBaytis
1.准备jar包 A.第一种方式:配置SqlSessionFactoryBean+配置SqlSessionTemplate a.项目结构 b.applicationContext.xml 带详细注释 ...
- Struts(十二):异常处理:exception-mapping元素
配置当前action的声明异常处理 1.exception-mapping元素中有2个属性 exception:指定需要捕获的异常类型 result:指定一个响应结果,该结果将在捕获到异常时被执行.即 ...
- POJ-2240 Arbitrage---判断正环+枚举
题目链接: https://vjudge.net/problem/POJ-2240 题目大意: 已知n种货币,以及m种货币汇率及方式,问能否通过货币转换,使得财富增加. 思路: 由于这里问的是财富有没 ...
- jquery中的attr()与prop()的区别
根据官方的建议:具有 true 和 false 两个属性的属性,如 checked, selected 或者 disabled 使用prop(),其他的使用 attr()
- 前端开发必备之Chrome开发者工具(下篇)
本文介绍的 Chrome 开发者工具基于 Chrome 65版本,如果你的 Chrome 开发者工具没有下文提到的那些内容,请检查下 Chrome 的版本 本文是 前端开发必备之Chrome开发者工具 ...
- 3分钟搞掂Set集合
前言 声明,本文用的是jdk1.8 前面章节回顾: Collection总览 List集合就这么简单[源码剖析] Map集合.散列表.红黑树介绍 HashMap就是这么简单[源码剖析] LinkedH ...
- [LeetCode] Exclusive Time of Functions 函数的独家时间
Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find ...