sindresorhus / run-applescript

Run AppleScript and get the result
MIT License
140 stars 15 forks source link

Can this be used with Electron? #13

Closed NL33 closed 3 years ago

NL33 commented 3 years ago

How can I properly import this with electron?

The readme here describes that to use run-applescript you should import it, like: import { runAppleScriptAsync } from 'run-applescript';

However, in Electron this leads to the error: SyntaxError: Cannot use import statement outside a module

If I try to change the syntax to: const { runAppleScriptAsync }= require('run-applescript')

This code produces this error:
Must use import to load ES Module

sindresorhus commented 3 years ago

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-import-esm-in-electron

NL33 commented 3 years ago

Thanks for the info here, but I am not yet able to get things to work. I have reviewed the resource you referenced, as well as the extended discussion about esm and Electron here. But there are some things about how esm works that I must be missing (I have not previously been familiar with the import / esm issue in electron).

I downloaded the esm package ($ npm i esm), and then brought it into my main.js per their docs:

require = require("esm")(module/*, options*/)
module.exports = require("./main.js")

But, still importing run-applescript in either my main js or renderer after bringing in esm, doesn't work. I've tried both:

import { runAppleScriptAsync } from './node_modules/run-applescript';

and const runAppleScriptAsync = require('run-applescript')

I see that another option is using webpack, but I would prefer to avoid significant changes to my structure (which does not use webpack).

is there another way to use this package with esm?

NL33 commented 3 years ago

Hi There. Still trying to find a way to use this with electron, but not having success yet. Trying to get this to work with ESM is currently a no-go it seems. And I'm not able to use webpack.

So, that leaves using a prior version that would allow a require statement.

From what I can tell, the last commit that would allow that would be this one from Jan 2021: https://github.com/sindresorhus/run-applescript/tree/dd9465af64f36e7775180997a20af0671ace43cd

Do you think that is acceptable for production for current version (12+) electron?