Closed NL33 closed 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
?
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?
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