Closed denfield-daveyonmayne closed 1 year ago
Hi @denfield-daveyonmayne - thanks for the message, is the purpose of the code shared to send an email?
Ah okay, I see, the code sample is creating email participants to send emails to.
Hi yes, to send a message per docs.
Think I see a potential issue. I'm importing that .js
file in a TypScript file. This may be the issue.
Let me try this out locally - I am suspecting it is the import (we only support CJS, ESM is in the pipeline)
So swapping import for require works:
const { default: EmailParticipant } = require('nylas/lib/models/email-participant');
and
const sendTo = new EmailParticipant({ email: to });
Hi @relaxedtomato in this application, we cannot use require. Is there another workaround using import
?
Okay, will spin up a TypeScript project with your config and take a look soon 👍
Sharing a related issue for context. I don't see a straightforward path until we support ESM (we are looking into this).
cc: @mrashed-dev
@denfield-daveyonmayne - let me know if the following works, going to test with your TS config next:
import EmailParticipant from "nylas/lib/models/email-participant.js";
const sendTo = new EmailParticipant.default({ email: 'email@email.com' });
I had to modify the TS config (first two items)
{
"compilerOptions": {
"target": "es2017",
"module": "es2022",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true,
"disableSizeLimit": true,
"allowJs": true,
"checkJs": false
}
}
Hi @relaxedtomato did you got it working on your end? I'm getting
error TS2339: Property 'default' does not exist on type 'typeof EmailParticipant'
I've also modified my compilerOptions
as what you have.
If you guys are working on an ES import then I'd use axios where needed until then. I'll close this thread and thanks for your time.
Sounds good @denfield-daveyonmayne, just an update: @mrashed-dev from our SDK team has shared that ESM support is going into active development in a sprint soon. We'll keep you posted!
Using v6.10.0 I got an error for
new EmailParticipant({..})
. A basic usage gives the error:Edited: I'm importing in a TypeScript file with compilerOptions: