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

Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Middleware pages/_middleware even if I don't use functions like eval and new Function #35203

Closed
1 task done
8byr0 opened this issue Mar 10, 2022 · 2 comments
Labels
bug Issue was opened via the bug report template.

Comments

@8byr0
Copy link

8byr0 commented Mar 10, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
Binaries:
Node: 14.18.2
npm: 6.14.15
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 17.0.2
react-dom: 17.0.2

What browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

N/A

Describe the Bug

next start and next dev work fine, but next build throws the following error:

Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Middleware pages/_middleware

This issue occurs even with a very simple middleware.

Expected Behavior

It should not trigger this error.

To Reproduce

Run a nextjs project with the following .babelrc

// .babelrc
{
  "presets": ["next/babel", "@babel/preset-typescript"],
  "plugins": ["relay", "istanbul]
}
@8byr0 8byr0 added the bug Issue was opened via the bug report template. label Mar 10, 2022
@8byr0
Copy link
Author

8byr0 commented Mar 10, 2022

I came across this issue and found a few similar ones reported:

There have been solutions proposed in there like disabling istanbul for a given file (#32608 (comment)) but since istanbul is used in testing environment I wanted to share another solution based on babel env feature:

// .babelrc
{
  "presets": ["next/babel", "@babel/preset-typescript"],
  "plugins": ["relay"],
  "env": {
    "test": {
      // override plugin configuration for testing env
      "plugins": ["relay", "istanbul"]
    }
  }
}

@8byr0 8byr0 closed this as completed Mar 10, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 9, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

1 participant