引入ElementUI 日历组件报错Module parse failed: Unexpected token (65:6)

简介: 引入ElementUI 日历组件报错Module parse failed: Unexpected token (65:6)

image.png

打开源码包找到日历组件所在位置,并引入


import DatePanel from "element-ui/packages/date-picker/src/panel/date.vue";

果不其然,报错了

Module parse failed: Unexpected token (65:6)
You may need an appropriate loader to handle this file type.
|     }, this.$slots.default);
|     const wrap = (
|       <div
|         ref="wrap"
|         style={ style }

最后有人帮忙解决了


1、安装依赖

https://github.com/vuejs/babel-plugin-transform-vue-jsx


npm install\
  babel-plugin-syntax-jsx\
  babel-plugin-transform-vue-jsx\
  babel-helper-vue-jsx-merge-props\
  babel-preset-env\
  --save-dev

2、添加vue-cli3的 vue.config.js配置


const path = require('path')
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('thejs')
      .test(/\.js$/)
      .include
        .add(path.resolve('src'))
        .add(path.resolve('node_modules/element-ui/packages'))
        .end()
      .use('babel-loader')
        .loader('babel-loader')
        .end()
  }
}

最后成功引入, 不过修改默认是隐藏的, 而且组件不接收参数,可以使用继承的方式将隐藏属性改为显示,业务页面再进行引入


<script>
import DatePanel from "element-ui/packages/date-picker/src/panel/date.vue";
export default {
  extends: DatePanel,
  data() {
    return {
      visible: true
    };
  }
};
</script>

image.png

相关文章
|
运维 JavaScript jenkins
uni-app命令行构建Module parse failed:Unexpected token错误处理
分享一次打包环境升级导致的jenkins部署流程失败问题的解决过程。
1668 0
|
7月前
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
|
7月前
|
资源调度 前端开发
编译第三方前端项目时候出现Syntax Error: TypeError: Cannot set properties of undefined (setting ‘parent‘)
编译第三方前端项目时候出现Syntax Error: TypeError: Cannot set properties of undefined (setting ‘parent‘)
497 0
|
4月前
|
JavaScript 前端开发
vue引入axios出现Module parse failed: Unexpected token (5:2)
vue引入axios出现Module parse failed: Unexpected token (5:2) 页面显示 Cannot GET /
148 2
|
7月前
vue2项目安装出现Syntax Error: Error: Cannot find module ‘less‘
vue2项目安装出现Syntax Error: Error: Cannot find module ‘less‘
114 0
Vue3.0+ts填坑 warning Unexpected any报类型警告
Vue3.0+ts填坑 warning Unexpected any报类型警告
141 0
|
Web App开发 JavaScript 前端开发
解决DevTools failed to load SourceMap Could not load content for .js.map HTTP error code 404 问题
解决DevTools failed to load SourceMap Could not load content for .js.map HTTP error code 404 问题
904 0
|
7月前
报错The above error occurred in the <InnerPicker> component:解决方法和Ant Design form表单setFieldValue修改input
报错The above error occurred in the <InnerPicker> component:解决方法和Ant Design form表单setFieldValue修改input
287 0
|
7月前
|
JavaScript
【Vue Error】 error Component name “product“ should always be multi-word vue/multi-word-compone……
【Vue Error】 error Component name “product“ should always be multi-word vue/multi-word-compone……
|
前端开发 JavaScript
Module build failed: TypeError: this.getResolve is not a function,vue写css时启动出错
Module build failed: TypeError: this.getResolve is not a function,vue写css时启动出错
50 0