You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron+Vue项目引入TypeORM报错:缺少对应文件加载器

问题:Electron + Vue 集成 TypeORM 时出现 Module parse failed 错误

运行项目时触发如下错误:

Module parse failed: Unexpected character '​' (2:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import { EntitySchema } from "typeorm"
> ​
| export default new EntitySchema({
|     name: "Post", // Will use table name `post` as default behaviour.

项目基于 Vue CLI 创建,无独立 webpack.config.js 文件。

涉及的实体文件 Category.js 代码:

import { EntitySchema } from "typeorm"

export default new EntitySchema({
    name: "Category", // Will use table name `category` as default behaviour.
    tableName: "categories", // Optional: Provide `tableName` property to override the default behaviour for table name.
    columns: {
        id: {
            primary: true,
            type: "int",
            generated: true,
        },
        name: {
            type: "varchar",
        },
    },
})

当前 Babel.config.js 配置:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ]
}

已尝试在 vue.config.js 中添加 transpileDependencies 配置,但问题未解决,配置内容如下:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: [
   'typeorm'
  ],
  configureWebpack: {
    devtool: 'source-map',
  },

  pluginOptions: {
    vuetify: {
            // https://github.com/vuetifyjs/vuetify-loader/tree/next/packages/vuetify-loader
        }
  }
})

参考过其他同类问题仍无法解决,寻求解决方案。

内容的提问来源于stack exchange,提问作者Lucas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 12:05:28