Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

babel transform error #54

Closed
quitone opened this issue Mar 13, 2021 · 1 comment
Closed

babel transform error #54

quitone opened this issue Mar 13, 2021 · 1 comment

Comments

@quitone
Copy link

quitone commented Mar 13, 2021

错误信息
Uncaught SyntaxError: The requested module '/src/app.vue?vue&type=script&lang.jsx' does not provide an export named 'default'
源码

<script lang="jsx">
  export default {
    data() {
      return {
        message: 'Hello world'
      }
    },
    render() {
      return (<div>{ this.message }</div>)
    }
  }
</script>

transformed

"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = void 0;
var _default = {
    data() {
        return {
            message: 'Hello world'
        };
    },

    render() {
        const h = arguments[0];
        return h("div", [this.message]);
    }

};
exports.default = _default;

babel 配置

module.exports = {
  "presets": [
    [
      "@babel/env",
      {
        "targets": {
          chrome: 80,
        },
        "useBuiltIns": "entry",
        "corejs": "3.9.1"
      }
    ]
  ]
}

依赖

{
  "dependencies": {
    "vue": "^2.6.12",
    "vue-template-compiler": "^2.6.12"
  },
  "devDependencies": {
    "@babel/cli": "7.13.10",
    "@babel/core": "7.13.10",
    "@babel/preset-env": "7.13.10",
    "@rollup/plugin-babel": "5.3.0",
    "@vue/babel-preset-jsx": "1.2.4",
    "core-js": "3.9.1",
    "sass": "^1.32.8",
    "vite": "2.0.5",
    "vite-plugin-vue2": "1.3.2"
  }
}

vite 配置

import { babel } from '@rollup/plugin-babel';
import { defineConfig } from 'vite';
import { createVuePlugin } from 'vite-plugin-vue2';

export default defineConfig({
  base: './',
  esbuild: {
    jsxFactory: 'h',
  },
  plugins: [
    babel(),
    createVuePlugin({
      jsx: true,
    })
  ]
})
@kouhin
Copy link

kouhin commented Mar 18, 2021

试试删除项目内的babel 配置文件,比如 .babelrc, babel.config.json 之类的

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants