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

Remove dynamic imports #16

Merged
merged 3 commits into from
Oct 12, 2023
Merged

Conversation

vlad-iliescu-tallarium
Copy link
Collaborator

Related to the following error:

Oct 11 16:52:55 [zed-qa](https://my.papertrailapp.com/systems/zed-qa/events?focus=1648790772319412303&selected=1648790772319412303) [zed-qa-0.8.1/82it4mwx](https://my.papertrailapp.com/events?q=program%3Azed-qa-0.8.1%2F82it4mwx&focus=1648790772319412303&selected=1648790772319412303) [error] - 2023-10-11T15:52:54.925Z - [77.98.48.199](https://my.papertrailapp.com/systems/zed-qa/events?q=%2277.98.48.199%22&focus=1648790772319412303&selected=1648790772319412303) - vlad: [BAILEYS] {"message":"Cannot find package 'axios' imported from C:\\Users\\viliescu\\AppData\\Local\\Tallarium\\Desktop Aggregator\\Application\\resources\\app.asar\\node_modules\\@whiskeysockets\\baileys\\lib\\Utils\\messages-media.js\nDid you mean to import axios/dist/node/axios.cjs?","stack":"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'axios' imported from C:\\Users\\viliescu\\AppData\\Local\\Tallarium\\Desktop Aggregator\\Application\\resources\\app.asar\\node_modules\\@whiskeysockets\\baileys\\lib\\Utils\\messages-media.js\nDid you mean to import axios/dist/node/axios.cjs?\n    at new NodeError (node:internal/errors:372:5)\n    at packageResolve (node:internal/modules/esm/resolve:954:9)\n    at moduleResolve (node:internal/modules/esm/resolve:1003:20)\n    at defaultResolve (node:internal/modules/esm/resolve:1218:11)\n    at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)\n    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)\n    at ESMLoader.import (node:internal/modules/esm/loader:380:22)\n    at importModuleDynamically (node:internal/modules/cjs/loader:1050:29)\n    at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)\n    at importModuleDynamically (node:vm:381:46)"} unexpected error in 'processing message'

Details on the actual issue

It looks like any dynamic import will fail once the app is packaged.
To be precise, it fails at the following line https://github.com/nodejs/node/blob/61712651a64fb3d7974d44378af3a4ee1676f287/lib/internal/modules/esm/resolve.js#L648
Skipping the check on the correct path does load the module correctly.
This seems to be related to the function not being able to read the directory within the .asar file as an actual path.
This is probably generic issue with electron apps from the looks of:
electron/electron#38957
electron/asar#249
Potentially fixed in electron/electron#37535 but this was just barely included in the latest electron 28.0.0 build so I'm reluctant to switch to that.

Solution

We can just replace all dynamic imports with static ones. From what I've read, it won't be that big of a loss

Why wasn't this occurring with the old version?

The dynamic imports were built to await Promise.resolve().then(() => __importStar(require('axios')));

const { default: axios } = await Promise.resolve().then(() => __importStar(require('axios')));
rather than await import('axios');
const { default: axios } = await import('axios');

I'm not sure what's causing the difference in build results. I assumed maybe my setup changed so I've tried checking out v4.2.0 but it built to the working version

@mwhitworth
Copy link

Sounds like we can upgrade Electron a bit later on to bring dynamic module importing back, and into a known supported state

@vlad-iliescu-tallarium vlad-iliescu-tallarium merged commit e949a4d into 6-5-0-patched Oct 12, 2023
0 of 2 checks passed
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