TS4090 Error: Conflicting libraries for node in electron

Viewed 577

hello,

I'm developing an electron app in typescript that breaks in compilation with the following error message (technically there're five of them, but they are all the same type of error, just conflicting with different parts)

node_modules/@types/body-parser/index.d.ts(12,23): error TS4090: Conflicting definitions for 'node' found at '.../node_modules/@types/node/index.d.ts' and './node_modules/electron/node_modules/@types/node/index.d.ts'. Consider installing a specific version of this library to resolve the conflict.

So this means that I have two type libraries for 'node' - however, I have not included a @types/node library in my package.json (as it is present in electron by default apparently). Therefore, I am utterly confused and lost on how to fix this.

I tried removing node_modules and yarn.lock and rebuilding the modules from scratch, removing either @types/node or electron/.../@types/node, even removing all code these refer to and gradually rebuilding them again. None worked. I also tried to use the solution mentioned here: https://github.com/electron/electron/issues/10167 but to no avail.

In the error message there is written 'Consider installing a specific version of this library to resolve the conflict' - how do I do that?

Hopefully that's enough info to go on,

Cheers

1 Answers

I have managed to solve my error, even though it was by way of more sidestepping it than actually understanding and solving the underlying problem. I suspected that having a single node_modules file for both a fairly complex UI tech stack and the electron stack.

I therefore separated these two into two separated sub-projects which are in compilation put together and combined that way. Of note is that in order to enable electron modules in the UI-project, I had to manually add it to the webpack.config.js file by adding this element to the plugins array

new webpack.ExternalsPlugin('commonjs', [
    'electron',
    'ipc',
    'ipc-renderer'
  ]),

So in conclusion, I no longer have the error, though I have not per-se solved it. I provide a short description of how I managed it in hopes that others encountering the same errors might be helped by this.

Cheers

Related