blitz-js / blitz-js/legacy-framework

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

Open
#4 2 comments 2 reactions 0 assignees View on GitHub
kind/bug legacy-framework status/ready-to-work-on
Dominant language
JavaScript
Stars
3
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.