Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron-forge的webpack插件编译问题:TS类型不匹配 #192

Open
shao-xy opened this issue Nov 16, 2024 · 1 comment
Open

Electron-forge的webpack插件编译问题:TS类型不匹配 #192

shao-xy opened this issue Nov 16, 2024 · 1 comment

Comments

@shao-xy
Copy link

shao-xy commented Nov 16, 2024

前言

首先声明我不是做前端的,仅仅是想简单二开自用。目前的问题是代码克隆到本地后无法编译。

问题

系统环境

  • Debian 10.10
  • Linux 内核 5.18.17
  • Node.js版本 v20.18.0
  • cnpm版本 9.4.0(npm版本9.9.2)
  • TypeScript版本 5.6.3
  • electron版本 25.3.0(eletron-forge及所有插件版本6.4.1)

操作步骤(稳定复现)

$ git clone [email protected]:shao-xy/MusicFreeDesktop
$ cd MusicFreeDesktop
$ cnpm install
$ cnpm start

最后一步出错:

> [email protected] start
> electron-forge start

✔ Checking your system
✔ Locating application
✔ Locating application
✖ Loading configuration
  › ⨯ Unable to compile TypeScript:
    forge.config.ts:51:7 - error TS2322: Type 'Configuration' is not assignable to type 'string | WebpackConfiguration'.
    Type 'import("/home/daniel/node_modules/webpack/types").Configuration' is not assignable to type 'import("/home/daniel/coding/app/MusicFreeD…
    Types of property 'entry' are incompatible.
       Type 'string | string[] | (() => string | string[] | import("/home/daniel/node_modules/webpack/types").EntryObject | Promise<EntryStatic>) |
    Type '() => string | string[] | EntryObject | Promise<EntryStatic>' is not assignable to type 'string | string[] | (() => string | string[] …
    Type '() => string | string[] | import("/home/daniel/node_modules/webpack/types").EntryObject | Promise<EntryStatic>' is not assignable to t…
    Type 'string | string[] | import("/home/daniel/node_modules/webpack/types").EntryObject | Promise<EntryStatic>' is not assignable to type 's…
    Type 'EntryObject' is not assignable to type 'string | string[] | EntryObject | Promise<EntryStatic>'.
    Type 'EntryObject' is missing the following properties from type 'string[]': length, pop, push, concat, and 29 more.
    51       mainConfig,
             ~~~~~~~~~~
    node_modules/.store/@electron-forge+plugin-webpack@6.4.1/node_modules/@electron-forge/plugin-webpack/dist/Config.d.ts:118:5
    118     mainConfig: WebpackConfiguration | string;
            ~~~~~~~~~~
    The expected type comes from property 'mainConfig' which is declared here on type 'WebpackPluginConfig'
    forge.config.ts:53:9 - error TS2322: Type 'Configuration' is not assignable to type 'string | WebpackConfiguration'.
    53         config: rendererConfig,
               ~~~~~~
    node_modules/.store/@electron-forge+plugin-webpack@6.4.1/node_modules/@electron-forge/plugin-webpack/dist/Config.d.ts:87:5
    87     config: WebpackConfiguration | string;
           ~~~~~~
    The expected type comes from property 'config' which is declared here on type 'WebpackPluginRendererConfig'
◼ Preparing native dependencies
◼ Running generateAssets hook

An unhandled rejection has occurred inside Forge:
TSError: ⨯ Unable to compile TypeScript:
forge.config.ts:51:7 - error TS2322: Type 'Configuration' is not assignable to type 'string | WebpackConfiguration'.
  Type 'import("/home/daniel/node_modules/webpack/types").Configuration' is not assignable to type 'import("/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/webpack@5.96.1/node_modules/webpack/types").Configuration'.                                                                  
    Types of property 'entry' are incompatible.
      Type 'string | string[] | (() => string | string[] | import("/home/daniel/node_modules/webpack/types").EntryObject | Promise<EntryStatic>) | import("/home/daniel/node_modules/webpack/types").EntryObject' is not assignable to type 'string | string[] | (() => string | string[] | import("/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/webpack@5.96.1/node_modules/webpack/types").EntryObject | Promise<...>) | import("/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/webpack@5.96.1/node_modules/webpack/types").EntryObject'.                                   
        Type '() => string | string[] | EntryObject | Promise<EntryStatic>' is not assignable to type 'string | string[] | (() => string | string[] | EntryObject | Promise<EntryStatic>) | EntryObject'.                                                                                             
          Type '() => string | string[] | import("/home/daniel/node_modules/webpack/types").EntryObject | Promise<EntryStatic>' is not assignable to type '() => string | string[] | import("/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/webpack@5.96.1/node_modules/webpack/types").EntryObject | Promise<EntryStatic>'.                                                                                                               
            Type 'string | string[] | import("/home/daniel/node_modules/webpack/types").EntryObject | Promise<EntryStatic>' is not assignable to type 'string | string[] | import("/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/webpack@5.96.1/node_modules/webpack/types").EntryObject | Promise<EntryStatic>'.                                                                                                                         
              Type 'EntryObject' is not assignable to type 'string | string[] | EntryObject | Promise<EntryStatic>'.
                Type 'EntryObject' is missing the following properties from type 'string[]': length, pop, push, concat, and 29 more.

51       mainConfig,
         ~~~~~~~~~~

  node_modules/.store/@electron-forge+plugin-webpack@6.4.1/node_modules/@electron-forge/plugin-webpack/dist/Config.d.ts:118:5
    118     mainConfig: WebpackConfiguration | string;
            ~~~~~~~~~~
    The expected type comes from property 'mainConfig' which is declared here on type 'WebpackPluginConfig'
forge.config.ts:53:9 - error TS2322: Type 'Configuration' is not assignable to type 'string | WebpackConfiguration'.

53         config: rendererConfig,
           ~~~~~~

  node_modules/.store/@electron-forge+plugin-webpack@6.4.1/node_modules/@electron-forge/plugin-webpack/dist/Config.d.ts:87:5
    87     config: WebpackConfiguration | string;
           ~~~~~~
    The expected type comes from property 'config' which is declared here on type 'WebpackPluginRendererConfig'
at createTSError (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/ts-node@10.9.2/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/ts-node@10.9.2/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/ts-node@10.9.2/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/ts-node@10.9.2/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/ts-node@10.9.2/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Object.require.extensions.<computed> [as .ts] (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/ts-node@10.9.2/node_modules/ts-node/src/index.ts:1621:12)                                                                                                                          
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at exports.default (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/@electron-forge+core@6.4.1/node_modules/@electron-forge/core/src/util/forge-config.ts:129:22)                                                                                                                    
    at async Task.task (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/@electron-forge+core@6.4.1/node_modules/@electron-forge/core/src/api/start.ts:63:29)                                                                                                                             
    at async Task.run (/home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/listr2@5.0.8/node_modules/listr2/dist/index.cjs:978:11)
    at async /home/daniel/coding/app/MusicFreeDesktop/node_modules/.store/p-map@4.0.0/node_modules/p-map/index.js:57:22

问题分析

我看了一下electron-forge的源码,WebpackConfiguration 是它自己内部从"webpack"的Configuration封装出的一个类型,但是为什么不兼容呢?大佬能不能提示一下?

@shao-xy shao-xy changed the title Eletron-forge的webpack插件编译问题:TS类型不匹配 Electron-forge的webpack插件编译问题:TS类型不匹配 Nov 16, 2024
@maotoumao
Copy link
Owner

代码拉到本地后有做什么改动嘛?会不会是cnpm的问题

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

No branches or pull requests

2 participants