Skip to content

Conversation

dynst
Copy link
Collaborator

@dynst dynst commented May 15, 2025

Electron 28 and newer has ESM support now.

package.json Outdated
"description": "WALLET AND EXCHANGE CLIENT FOR THORCHAIN, MAYACHAIN, CHAINFLIP",
"main": "build/main/electron.js",
"type": "module",
"exports": "build/main/electron.js",
Copy link
Collaborator

@Naq302 Naq302 May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When "type": "module", is added exports": "build/main/electron.js" shows a `String does not match the pattern of "^./". warning.

yarn dev fails
error during start dev server and electron app:
Error: No entry point found for electron app, please add a "main" field to package.json

Could be fixed via

"main": "./build/main/electron.js",
  "exports": {
    ".": "./build/main/electron.js"
  },

@dynst dynst marked this pull request as draft May 15, 2025 23:55
@dynst dynst marked this pull request as ready for review May 16, 2025 02:50
@Naq302
Copy link
Collaborator

Naq302 commented May 16, 2025

@dynst getting an error when doing a rebuild:

start electron app...

App threw an error during load
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/asgardex-desktop/node_modules/fp-ts/lib/Either' imported from /asgardex-desktop/build/main/electron.js
Did you mean to import "fp-ts/lib/Either.js"?
A JavaScript error occurred in the main process
Uncaught Exception:

Not sure why as Either is imported and present. I assume they need to be imported differently in electron.ts but not sure.

@dynst
Copy link
Collaborator Author

dynst commented May 16, 2025

ESM import distinguishes between importing /Either and /Either.js, the filename extension is the difference there. But there shouldn't be a difference, if Vite is specifically configured to search for .ts and .js files if an extension is omitted:

extensions: ['.ts', '.js']

https://vite.dev/config/shared-options#resolve-extensions

But that field has a decent default, anyway, even if it wasn't set. And it's only applicable to internal files, not for external dependencies.

I guess we're not supposed to reach into the /lib/ internal directory structure of a dependency. Instead we should:

import { either as E } from 'fp-ts'

There's a lot of import statements just like this one that bypass the module's official top-level export API, and they'll all need rewriting.

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

Successfully merging this pull request may close these issues.

2 participants