简体   繁体   中英

Why npm email templates won't load?

I use the npm library email-temaplates on several NodeJS apis deployed on the same environment with the same configuration.

node: v10.16.0
npm: 3.10.10
email-templates: 8.1.0
mailparser: 3.6.2
html-to-text@8.2.1

When the library is imported,

const Email = require('email-templates');

I have the following error on one of my apis:

...node_modules/mailparser/node_modules/html-to-text/lib/html-to-text.cjs:1838
2022-12-21 10:52 +01:00:     tableToString: (rows) => tableToString(rows, formatOptions.rowSpacing ?? 0, formatOptions.colSpacing ?? 3),

Despite the exact same code is working on the others apis.

The only difference is in the file package-lock.json . Oddly, the dependencies with html-to-text listed aren't the same even if the package.json are the same.

Here is the package.json file:

{
 "dependencies": {
    "async-redis": "^2.0.0",
    "axios": "^0.27.2",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "cookie-parser": "^1.4.5",
    "cors": "^2.8.5",
    "ejs": "^3.1.5",
    "email-templates": "^8.0.1",
    "express": "^4.17.1",
    "express-basic-auth": "^1.2.1",
    "express-fileupload": "^1.2.0",
    "express-validator": "^6.7.0",
    "helmet": "^4.2.0",
    "jwt-simple": "^0.5.6",
    "mime-types": "^2.1.34",
    "moment": "^2.29.1",
    "mongodb": "^3.7.3",
    "morgan": "^1.10.0",
    "mysql2": "^2.2.5",
    "node-cron": "^2.0.3",
    "nodemailer": "^6.4.16",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "redis": "^3.1.2",
    "socket.io": "2",
    "socketio-jwt": "^4.6.2",
    "swagger-jsdoc": "^6.2.1",
    "swagger-ui-express": "^4.3.0",
    "uuid": "^8.3.1",
    "winston": "^3.3.3"
  },
  "devDependencies": {
    "dotenv": "^8.2.0",
    "nodemon": "^2.0.6"
  }
}

I've tried other versions of the npm library email-templates (10.0.1, 10.0.0, 9.0.0) but each time, its the same result.

I've tried to rollback to a previous version of my API, it's working despite the package configuration (package.json) and the usage of that library is exactly the same than the ones of the newer version of my API. I'm stuck since few days now:/.

Execute

npm cache verify
rm -rf node_modules
rm package-lock.json
npm install

That will clean up and recreate the package-lock.json Sure you are using everywhere same node version.

Hint. Node 10 is very old Run

npm audit

This will analyse the vunerabilities.

If this doesnt help, post your package.json.

UPDATE

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "create a new folder inside execute:",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "async-redis": "^2.0.0",
    "axios": "^0.27.2",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "cookie-parser": "^1.4.5",
    "cors": "^2.8.5",
    "ejs": "^3.1.5",
    "email-templates": "^6.0.1",
    "express": "^4.17.1",
    "express-basic-auth": "^1.2.1",
    "express-fileupload": "^1.2.0",
    "express-validator": "^6.7.0",
    "helmet": "^4.2.0",
    "jwt-simple": "^0.5.6",
    "mime-types": "^2.1.34",
    "moment": "^2.29.1",
    "mongodb": "^3.7.3",
    "morgan": "^1.10.0",
    "mysql2": "^2.2.5",
    "node-cron": "^2.0.3",
    "nodemailer": "^6.4.16",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "redis": "^3.1.2",
    "socket.io": "2",
    "socketio-jwt": "^4.6.2",
    "swagger-jsdoc": "^6.2.1",
    "swagger-ui-express": "^4.3.0",
    "uuid": "^8.3.1",
    "winston": "^3.3.3"
  },
  "devDependencies": {
    "dotenv": "^8.2.0",
    "nodemon": "^2.0.6"
  }
}

node version 10.13.0

index.js

const Email = require('email-templates');
console.log(Email)

just to check the error

node index
[Function: Email]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM