Skip to content

convert from CJS to ESM - #712

Draft
dynst wants to merge 5 commits into
developfrom
esmify
Draft

convert from CJS to ESM#712
dynst wants to merge 5 commits into
developfrom
esmify

Conversation

@dynst

@dynst dynst commented May 15, 2025

Copy link
Copy Markdown
Collaborator

Electron 28 and newer has ESM support now.

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

@Naq302 Naq302 May 15, 2025

Copy link
Copy Markdown
Collaborator

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

Naq302 commented May 16, 2025

Copy link
Copy Markdown
Collaborator

@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

dynst commented May 16, 2025

Copy link
Copy Markdown
Collaborator Author

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