美文网首页
Error: Cannot find module ‘babel

Error: Cannot find module ‘babel

作者: 冰点雨 | 来源:发表于2022-06-24 19:36 被阅读0次

问题

安装element-ui后报错

 ERROR  Error: Cannot find module 'babel-plugin-component'
        Require stack:
        - /Users/liusy/Desktop/vue/shangpinhui/node_modules/@babel/core/lib/config/files/plugins.js
        - /Users/liusy/Desktop/vue/shangpinhui/node_modules/@babel/core/lib/config/files/index.js
        - /Users/liusy/Desktop/vue/shangpinhui/node_modules/@babel/core/lib/index.js
        - /Users/liusy/Desktop/vue/shangpinhui/node_modules/@vue/cli-plugin-babel/index.js
        - /Users/liusy/Desktop/vue/shangpinhui/node_modules/@vue/cli-service/lib/Service.js
        - /Users/liusy/Desktop/vue/shangpinhui/node_modules/@vue/cli-service/bin/vue-cli-service.js
Error: Cannot find module 'babel-plugin-component'

解决方法

1.安装:babel-plugin-component

npm install babel-plugin-component -D

2.在目前的vue脚手架项目中,更改:babel.config.js中的配置,把es2015改为@babel/env。如:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
    ["@babel/env", { "modules": false }]
  ],
  plugins: [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

相关文章

网友评论

      本文标题:Error: Cannot find module ‘babel

      本文链接:https://www.haomeiwen.com/subject/alrbvrtx.html