next.js: swcMinify: true - ReferenceError: Can't find variable: excludeEmptyString

What version of Next.js are you using?

12.0.1

What version of Node.js are you using?

16.10.0

What browser are you using?

Safari

What operating system are you using?

MacOS

How are you deploying your application?

Vercel

Describe the Bug

I’m sure its connected to other issues, but thought I’d provide some more context.

Setting the swcMinify config to true seems to break something in the runtime as it successfully builds and deploys, but then when navigating to certain pages I get:

ReferenceError: Can't find variable: excludeEmptyString 
  matches — string.js:75
  (anonymous function) — <some-page>.tsx:33
  g — bootstrap:22
  (anonymous function) — _N_E:6
  promiseReactionJob

Expected Behavior

Not error 😃

To Reproduce

Our team has a boilerplate repo we use on all our projects:

https://github.com/NoQuarterTeam/boilerplate

  • cd into packages/web
  • change the next.config.js file to set swcMinify to true
  • yarn build
  • yarn start
  • Navigate to /login

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 21 (7 by maintainers)

Most upvoted comments

@JClackett it’s yup package, maybe you have some custom validations.

We have come across a similar issue with yup email: Yup.string().email(t('validEmail')).required(t('required'))

ReferenceError: excludeEmptyString is not defined
at Ec.matches
at Ec.email

@JClackett it’s yup package, maybe you have some custom validations.

Yeah I do! is this documented as to why this wouldn’t work with swc minification? and if there’s a fix?

Example yup code:

import * as Yup from "yup"

Yup.addMethod(Yup.string, "nullIfEmpty", function () {
  return this.transform((val, origVal) => (origVal.trim() === "" ? null : val)).nullable()
})

Yup.addMethod(Yup.number, "nullIfEmpty", function () {
  return this.transform((val, origVal) => (origVal === "" ? null : val)).nullable()
})
export default Yup

Hey @rodilo!

Yeah, I get that too. If it’s yup your using, it seems the swc compiler is incompatible with yup version >0.32.10. You can use a lower version like yup version ^0.32.9 or set swcMinify: false

I also think there is a canary version of Next 12 that addresses this issue. You can use install next@canary and redeploy to production.