nest-modules / mailer

📨 A mailer module for Nest framework (node.js)
https://nest-modules.github.io/mailer/
MIT License
847 stars 177 forks source link

Error: Cannot find module '@css-inline/css-inline-linux-arm64-musl when starting application #1209

Open jaqarrick opened 5 months ago

jaqarrick commented 5 months ago

Describe the bug When I am starting my nest app I see the following error:

worker-1  | Error: Cannot find module '@css-inline/css-inline-linux-arm64-musl'
worker-1  | Require stack:
worker-1  | - /app/node_modules/@css-inline/css-inline/index.js
worker-1  | - /app/node_modules/@nestjs-modules/mailer/dist/adapters/ejs.adapter.js
worker-1  | - /app/dist/apps/worker/main.js
worker-1  |     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
worker-1  |     at Module.Hook.Module.require (/app/node_modules/dd-trace/packages/dd-trace/src/ritm.js:54:29)
worker-1  |     at require (node:internal/modules/helpers:177:18)
worker-1  |     at Object.<anonymous> (/app/node_modules/@css-inline/css-inline/index.js:206:31)
worker-1  |     at Module._compile (node:internal/modules/cjs/loader:1364:14)
worker-1  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
worker-1  |     at Module.load (node:internal/modules/cjs/loader:1203:32)
worker-1  |     at Function.Module._load (node:internal/modules/cjs/loader:1019:12)
worker-1  |     at Module.require (node:internal/modules/cjs/loader:1231:19)
worker-1  |     at Module.Hook.Module.require (/app/node_modules/dd-trace/packages/dd-trace/src/ritm.js:85:33)

This occurred after upgrading to 2.0.2 of @nestjs-modules/mailer I am using v18.19.0 of node

There are a couple closed versions of this issue or a similar one (#1128 and #1146) but the solution listed there is to downgrade the package or the node version.

Older versions of the mailer package have critical security vulnerabilities by requiring vm2 for example. So a better solution is needed.

AdiMarianMutu commented 4 months ago

Having the same issue, is there any solution or workaround which does not require to downgrade?

[EDIT]

A temporary fix is to "manually" install the missing dependency during the deployment.

DonWasyl commented 4 months ago

Have similar issue but with @css-inline/css-inline-freebsd-x64 Unfortunately, I can't find dependency to install it temporary

matissePe commented 4 months ago

Try to just npm remove @nestjs-modules/mailer then npm i @nestjs-modules/mailer It worked for me

jaqarrick commented 4 months ago

That didn't work unfortunately.

Also tried manually installing the missing dependency and got

yarn add @css-inline/css-inline-linux-arm64-musl 
...

error @css-inline/css-inline-linux-arm64-musl@0.14.1: The platform "darwin" is incompatible with this module.
error Found incompatible module.
josebright commented 4 months ago

Hello @jaqarrick, I think I figured out the issue.

Go to the files directory inside your docker and confirm if the files were mounted. Example of files that is not mounted is below otherwise you will see mount:

image

If it is mounted, then you will need to remove volumes from your app service in the docker-compose.yml file. Sample of my file is below:

version: '3.8'
services:
  postgres:
    image: postgres
    restart: always
    env_file:
      - .env
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - '5434:5432'
    volumes: 
      - goeliteapp:/var/lib/postgresql/data

  app:
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - postgres
    container_name: api-project
    working_dir: /app
    restart: always
    env_file:
      - .env
    environment:
      ENVIRONMENT: ${ENVIRONMENT}
      PORT: 3000
      DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?schema=public
    ports:
      - "3030:3000"
    command: ["/bin/sh", "-c", "./entrypoint.sh"]   #This is because I am using a script

volumes:
  goeliteapp:

Also, include the below in your .dockerignore .DS_Store /src/.DS_Store

After that, run the below commands and your docker will work properly:

docker compose down
docker compose build build --no-cache
docker compose up
kerimovok commented 3 months ago

@jaqarrick just add this to your package.json

"optionalDependencies": {
  "@css-inline/css-inline-linux-arm64-musl": "0.14.1"
}
Matisds commented 2 months ago

Encountering the same issue. I'm trying to run my Nest.JS project locally using Docker, hostmachine is Intel Mac, Docker version is node:20-alpine.

Reverting to 1.10.3 works but not a long-term solution due to security issues in older versions. Adding optionalDependencies like @kerimovok suggestud does not work either.

If someone could help in providing a solution that would be great! I'm happy to assist where needed.

@jaqarrick How did you end up handling the issue?

jaqarrick commented 2 months ago

Not idea, but I ended up forking the package and adding the module directly in my repo. This allowed me to manually upgrade and manage the dependencies. @Matisds

raphaelcomph-dev commented 2 months ago

I just install it as one of the steps in my Dockerfile

...

# Step 5: Install dependencies
RUN npm install

# Adding temporarily due to update failed on @nestjs-modules/mailer
RUN npm install @css-inline/css-inline-linux-x64-musl

# Step 6: Copy the rest of the application code
COPY . .

# Step 7: Build the NestJS app
RUN nest build

...