Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swcMinify: true - ReferenceError: Can't find variable: excludeEmptyString #30429

Closed
JClackett opened this issue Oct 27, 2021 · 21 comments
Closed
Assignees
Labels
kind: bug Confirmed bug that is on the backlog

Comments

@JClackett
Copy link
Contributor

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
@JClackett JClackett added the bug Issue was opened via the bug report template. label Oct 27, 2021
@mr47
Copy link
Contributor

mr47 commented Oct 27, 2021

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

@JClackett
Copy link
Contributor Author

@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

@ScottEAdams
Copy link

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

@timneutkens timneutkens added area: SWC Minify kind: bug Confirmed bug that is on the backlog and removed bug Issue was opened via the bug report template. labels Oct 31, 2021
@timneutkens timneutkens added this to the 12.0.x milestone Oct 31, 2021
@jamesbluecrow
Copy link

jamesbluecrow commented Nov 1, 2021

I'm seeing a similar issue when swcMinify: true, the error I see is:

NextJS Version 12.0.2

Uncaught SyntaxError: Missing initializer in const declaration

@MohammedWaheeb
Copy link

same issue here with 12.0.1 and yup 0.32.9 swcMinify: true

@neilpoulin
Copy link

This is related to my issue posted here: #30498

@mntnv
Copy link

mntnv commented Nov 3, 2021

I'm having the same issue with yup v0.32.9 and the same behavior with the latest version.

for me, a temporary downgrade to yup v0.31.1 helped to fix ReferenceError: Can't find variable: excludeEmptyString

On the next.js v12 with enabled swcMinify.

@styfle styfle modified the milestones: 12.0.x, 12.0.4 Nov 5, 2021
@rpedroni
Copy link

rpedroni commented Nov 6, 2021

Having same issue with email validation with "yup": "^0.32.9"
Turning off swcMinify for now while stability pending

@Aliemeka
Copy link

Aliemeka commented Nov 9, 2021

I think setting swcMinify: false solves the issue for me. However, there needs to be support for yup version ^0.32.11 validations.

@egaba
Copy link

egaba commented Nov 9, 2021

Having a similar issue using v12.0.3 and yup. Going to turn off swcMinify for now.

@nikosantis
Copy link
Contributor

Same issue with Nextjs v12.0.3 and yup 0.32.11.

ReferenceError: excludeEmptyString is not defined
    at yc.matches (545-7eafa77df153ad02.js:1)
    at yc.email (545-7eafa77df153ad02.js:1)
    at Object.7669 (index-5f41350bcbc82045.js:1)
    at g (webpack-2bbe73903b6b5b3e.js:1)
    at index-5f41350bcbc82045.js:1
    at main-5a40b9d72bc92c69.js:1

@kdy1
Copy link
Member

kdy1 commented Nov 11, 2021

I think this is fixed by #31242

@neilpoulin
Copy link

I think this is fixed by #31242

Great! I'll test it once that commit gets released.

@timneutkens
Copy link
Member

@neilpoulin you can try it using npm install next@canary 👍

@timneutkens timneutkens removed this from the 12.0.5 milestone Nov 17, 2021
@rodilo
Copy link

rodilo commented Nov 24, 2021

I'm seeing a similar issue when swcMinify: true, the error I see is:

NextJS Version 12.0.2

Uncaught SyntaxError: Missing initializer in const declaration

Did you find what was causing your issue? I get the same when I enable swcMinify.

@Aliemeka
Copy link

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.

@rodilo
Copy link

rodilo commented Nov 24, 2021

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.

I've found what was causing mine, it's ajv. So I'll try to upgrade to the latest version, and see if the error still occurs.

@rodilo
Copy link

rodilo commented Nov 24, 2021

Yeah, I get the same error with the canary version as well.
Error is thrown from within ajv library we use for validation.

@BluetyIt
Copy link

BluetyIt commented Dec 2, 2021

I got same error while using next^12.0.2
Fixed while upgrade to next^12.0.4

@timneutkens
Copy link
Member

timneutkens commented Dec 23, 2021

The issue with yup has been fixed on the latest stable as @BluetyIt mentioned.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: bug Confirmed bug that is on the backlog
Projects
None yet
Development

No branches or pull requests