mailer module missing dependency?

Support

I wrote nothing but

import sendEmail from "@factor/api/server"

in index.js on root
and I get Module not found error

./node_modules/nodemailer/lib/smtp-connection/index.js        
Module not found: Error: Can't resolve 'tls' in '/~directories~to~app~/node_modules/nodemailer/lib/smtp-connection

I can import addRoute, so I'm sure I have @factor/api module.
did I miss anything while setup?

Just rerun your npm install

its possible there is something out of order in node_modules

"dependencies": {
    "@factor/api": "^1.7.10",
    "@factor/core": "^1.7.10"
  },

reran 'npm init' and 'npm install'
everything is installed without error, and I still get

 90% additional chunk assets processing
 ERROR  Module not found: Error: Can't resolve 'child_process' in /~~directory/
 ...
 Module not found: Error: Can't resolve 'child_process' in /~~directory/
 ...
 Module not found: Error: Can't resolve 'dns' in /~~directory/
 ...
 it goes on for like 10 more moudle not found error

Ah I know, you are including the server side email stuff in the app.

What's happening is that in the "client" or browser it doesnt have stuff like child_process which is a node/server thing.

Read up on Main files

make sure that server api stuff doesnt get loaded in the "app" environment.

Email sending or DB code falls into that category.

Makes sense
solved. :)

Another error while working on email

server_1.default is not a function in contact-email:sendContactEmail

ERROR  server_1.default is not a function                            21:46:40

at Object.exports.sendContactEmail (server.js:27:21)
  at Object.exports.runEndpointMethod (node_modules/@factor/endpoint/server.ts:66:33)
at handler (node_modules/@factor/endpoint/server.ts:125:58)
  at Object.exports.processEndpointRequest (node_modules/@factor/endpoint/server.ts:99:37)
at process._tickCallback (internal/process/next_tick.js:68:7)

Endpoint method works as param consoles clients request.

export const sendContactEmail = async (params, meta) => {
    console.log(params);

    const emailConfig = {
      subject: "Email Subject",
      to: ["[email protected]"], 
      from: params.mail, // set this optionally, it defaults to app email
      title: "Title text in the email",
      text: params.coop+','+
            params.name+','+
            params.tel+','+
            params.mail+','+
            params.curri+','+
            params.sm+'월'+params.sd+'일 ~ '+params.em+'월'+params.ed+'일'+
            params.curri+','+
            params.etc
    }

    console.log(emailConfig);
  
    await sendEmail(emailConfig);
    
    // await sendEmailToId(_id, emailConfig)
}

That looks like an import issue, what are you importing into the file?

Also install eslint import and TypeScript to get warnings about things before they turn into runtime errors

server.js

import sendEmail from "@factor/api/server"
import { addEndpoint } from "@factor/api"

console.log('served');

export const sendContactEmail = async (params, meta) => {
    console.log(params);

    const emailConfig = {
      subject: "Email Subject",
      to: ["[email protected]"], 
      from: params.mail, // set this optionally, it defaults to app email
      title: "Title text in the email",
      text: params.coop+','+
            params.name+','+
            params.tel+','+
            params.mail+','+
            params.curri+','+
            params.sm+'월'+params.sd+'일 ~ '+params.em+'월'+params.ed+'일'+
            params.curri+','+
            params.etc
    }

    console.log(emailConfig);
		// emailConfig prints valid object
  
    await sendEmail(emailConfig); 
}

addEndpoint({
    id: "contact-email",
    handler: { sendContactEmail },
})

client-side vue script

import { endpointRequest } from "@factor/api";
export default {
    data:function(){
        return{
            coop:"",
            name:"",
            ...
        }
    },
    methods:{
        sendContact:function(){
            var res = endpointRequest({
                id: "contact-email",
                method: "sendContactEmail",
                params: { 
                    coop: this.coop ,
                    name:this.name,
                    ...
                },
            }).then((res)=>{
                console.log(res)
            })
        }
    }
}

package.json

{
  "name": "edu",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@factor/api": "^1.7.10",
    "@factor/core": "^1.7.10",
  },
  "factor": {
    "app": {
      "name": "edu",
      "description": "Education Contact"
    },
    "load": {
      "app": "index",
      "server": [
        "index",
        "server"
      ]
    }
  },
  "description": ""
}

The error is because you are importing sendEmail as default import instead of a named import:

import {sendEmail} from "@factor/api"

Also, you don't need to add @factor/api as a dependency since it's loaded by the core.

Finally, always use async/await instead of standard promises with then

All works well after changing to {sendEmail}

Why would you recommend async/await over then?

isn't it the same thing?

10