electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.41k stars 506 forks source link

logs4js error in main process #1726

Closed fragoulin closed 3 years ago

fragoulin commented 4 years ago

Preflight Checklist

Issue Details

Expected Behavior

I want to use log4js (https://github.com/log4js-node/log4js-node)

Actual Behavior

Creating a simple logger fails when starting electron, in extension https://github.com/MarshallOfSound/webpack-asset-relocator-loader This extension is installed when following steps in https://www.electronforge.io/templates/typescript-+-webpack-template

To Reproduce

  1. $ yarn create electron-app my-new-app --template=typescript-webpack
  2. $ yarn add log4js
  3. add the following code to index.ts file :
    import log4js from 'log4js'
    const logger = log4js.getLogger()
    logger.log('main process')

Additional Information

Error trace : $ yarn start

yarn run v1.22.4 $ electron-forge start √ Checking your system √ Locating Application √ Preparing native dependencies √ Compiling Main Process Code

  • Launch Dev ServersStarting type checking service... Using 1 worker with 2048MB memory limit √ Launch Dev Servers √ Compiling Preload Scripts √ Launching Application

Webpack Output Available: http://localhost:9000

App threw an error during load Error: Module build failed (from ./node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js): SyntaxError: Unexpected token (86:14) at Object.module.exports.pp$4.raise (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:20834:13) at Object.module.exports.pp.unexpected (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:18680:8) at Object.module.exports.pp$1.parseTryStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:19069:49) at Object.module.exports.pp$1.parseStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:18834:32) at Object.parseStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:4539:118) at Object.parseStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:42314:22) at Object.module.exports.pp$1.parseBlock (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:19157:23) at Object.module.exports.pp$1.parseTryStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:19073:24) at Object.module.exports.pp$1.parseStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:18834:32) at Object.parseStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:4539:118) at Object.parseStatement (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:42314:22) at Object.module.exports.pp$1.parseBlock (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:19157:23) at Object.module.exports.pp$3.parseFunctionBody (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:20675:22) at Object.module.exports.pp$3.parseArrowExpression (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:20638:8) at Object.module.exports.pp$3.parseExprAtom (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:20227:21) at Object.parseExprAtom (C:\Users\fab\source\repos\my-new-app\node_modules\@marshallofsound\webpack-asset-relocator-loader\dist\index.js:4551:117) at Object../node_modules/fs-extra/lib/mkdirs/make-dir.js (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:2451:7) at webpack_require__ (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:21:30) at Object../node_modules/fs-extra/lib/mkdirs/index.js (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:2428:44) at webpack_require (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:21:30) at Object../node_modules/fs-extra/lib/copy-sync/copy-sync.js (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:1368:20) at __webpack_require (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:21:30) at Object../node_modules/fs-extra/lib/copy-sync/index.js (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:1545:13) at webpack_require__ (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:21:30) at Object../node_modules/fs-extra/lib/index.js (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:2294:6) at webpack_require__ (C:\Users\fab\source\repos\my-new-app.webpack\main\index.js:21:30) Type checking in progress... webpack built 4444f6a00c07388e4c85 in 904ms No type errors found Version: typescript 3.9.3 Time: 2712ms

This error is due to a catch statement without parameter in fs-extra extension :

      try {
        const stats = await fs.stat(pth)
        if (!stats.isDirectory()) {
          // This error is never exposed to the user
          // it is caught below, and the original error is thrown
          throw new Error('The path is not a directory')
        }
      } catch {
        throw error
      }

MarshallOfSound extension cannot handle catch statements without parameters, but it's valid JS.

Reproduced on this repository : https://github.com/fragoulin/my-new-app

Andreybest commented 4 years ago

Having the same issue with discord.js, does anybody have workaround for this, or we need to wait for a bug fix?

barbalex commented 4 years ago

I get this when updating from v6.0.0-beta.50 to v6.0.0-beta.52, 6.0.0-beta.53 or 6.0.0-beta.54

JasinYip commented 3 years ago

Any news? facing the same error here 😢

malept commented 3 years ago

This seems like a general Webpack issue and not Electron Forge specific. See: https://github.com/log4js-node/log4js-node/issues/968

I've also verified that there are errors regardless of whether the asset relocator plugin is enabled in the Webpack config.

Since it seems like there's nothing actionable that we can do on the Electron Forge side, I'm closing this bug.