blitz-js / legacy-framework

MIT License
2 stars 2 forks source link

Cannot find module 'preview-email' or its corresponding type declarations in production deploy #4

Open mltwist-brice opened 2 years ago

mltwist-brice commented 2 years ago

What is the problem?

When deploying/building for production, Blitzjs fails to find the dynamic import for preview-email when checking the validity of types. This is the code that comes out of the box with a new Blitzjs project in the ./mailers/forgotPasswordMailer.ts file. I suspect the production build tree shakes, removes the preview email dependency and even though the dynamic importing of the preview-email library should only occur in dev, it still thinks it is missing and fails to build.

Paste all your error logs here:

info  - Generating route manifest...
info  - Checking validity of types...
Failed to compile.
Apr 28 03:55:08 PM   
./mailers/forgotPasswordMailer.ts:44:44
Type error: Cannot find module 'preview-email' or its corresponding type declarations.
Apr 28 03:55:08 PM  
  42 |       } else {
  43 |         // Preview email in the browser
> 44 |         const previewEmail = (await import("preview-email")).default
     |                                            ^
  45 |         await previewEmail(msg)
  46 |       }
  47 |     },
==> Build failed 😞

Paste all relevant code snippets here:

The block of code from forgotPasswordMailer.ts

return {
    async send() {
      if (process.env.NODE_ENV === "production") {
        // TODO - send the production email, like this:
        await SendGrid.sendEmail(msg)
        throw new Error("No production email implementation in mailers/forgotPasswordMailer")
      } else {
        // Preview email in the browser
        const previewEmail = (await import("preview-email")).default
        await previewEmail(msg)
      }
    },
  }

What are detailed steps to reproduce this?

  1. Create a new blitz project
  2. run NODE_ENV=production yarn install --frozen-lockfile && blitz prisma generate && blitz build && blitz prisma migrate deploy && yarn start

Run blitz -v and paste the output here:

macOS | darwin-x64 | Node: v14.17.0

blitz: 0.45.4 (global)
blitz: 0.45.4 (local)

  Package manager: yarn 
  System:
    OS: macOS 12.0.1
    CPU: (8) x64 Apple M1
    Memory: 20.22 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - ~/.asdf/installs/nodejs/14.17.0/bin/node
    Yarn: 1.22.17 - ~/.asdf/installs/nodejs/14.17.0/.npm/bin/yarn
    npm: 8.6.0 - ~/.asdf/plugins/nodejs/shims/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 3.12.0 => 3.12.0 
    blitz: 0.45.4 => 0.45.4 
    prisma: 3.12.0 => 3.12.0 
    react: 18.0.0 => 18.0.0 
    react-dom: 18.0.0 => 18.0.0 
    typescript: ~4.5 => 4.5.5 

Please include below any other applicable logs and screenshots that show your problem:

No response

beerose commented 2 years ago

Thanks for the issue. We'll try to look into it soon

jamesmcintyre commented 2 years ago

Having the same issue. Any guidance on a temporary fix for this? @beerose @mltwist-brice