Search code examples
vue.jstypeormelectron-builder

building electron app with Vue CLI Plugin Electron Builder (cannot access 'fa' before initialization) - TypeORM association ManyToOne


I have an electron app project that run perfectly in dev mode with webpack dev server and vue-cli-service.

Now I want to package my application for production distribution.

For that I use the Vue CLI Plugin Electron Builder library and launch this command :

  "electron:build": "vue-cli-service electron:build"

All seems to be good. Nothing errors or interrupt process. But when I launch my new app installation I have error in startup like this :

     A JavaScript error occurred in the main process

    Uncaught Exception:
    ReferenceError: Cannot access 'fa' before initialization
    at Module.<anonymous> (/Applications/electrony.app/Contents/Resources/app.asar/background.js:2:1550520)
    at n (/Applications/electrony.app/Contents/Resources/app.asar/background.js:2:110)
    at Object.<anonymous> (/Applications/electrony.app/Contents/Resources/app.asar/background.js:2:110880)
    at n (/Applications/electrony.app/Contents/Resources/app.asar/background.js:2:110)
    at /Applications/electrony.app/Contents/Resources/app.asar/background.js:2:902
    at Object.<anonymous> (/Applications/electrony.app/Contents/Resources/app.asar/background.js:2:913)
    at Module._compile (internal/modules/cjs/loader.js:967:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1004:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Module._load (internal/modules/cjs/loader.js:727:14)

If a inspect the background.js file I can view that :

S([Object(z.ManyToOne)(()=>fa,a=>a.association,{nullable:!0,cascade:["insert","update"],eager:!0}),x("design:type","function"==typeof(b=void 0!==fa&&fa)?b:Object)]

It seems that dealing with TypeORM entity association ManyToOne declaration. But I don't understand what is the 'fa' is this context because nothing declaration of 'fa' library or object exist in that entity file.

Have you already packaged electron app with TypeORM library ?


Solution

  • I solve my issue by change the tsconfig.json file

    from this :

      "lib": ["es5", "es6", "dom"],
      "module": "esnext",
      "target": "es6",
      "moduleResolution": "node",
      "noImplicitAny": true,
      "removeComments": true,
      "preserveConstEnums": true,
      "sourceMap": true,
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "esModuleInterop": true,
    

    to this :

      "lib": ["es5", "es6", "dom"],
      "module": "commonjs",
      "target": "esnext",
      "types": ["node", "jest"]
      "moduleResolution": "node",
      "noImplicitAny": true,
      "removeComments": true,
      "preserveConstEnums": true,
      "sourceMap": true,
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "esModuleInterop": true,
    

    Now the generated files entities have no circular declaration problem.