next.js: Next 12.2 ReferenceError: exports is not defined

Verify canary release

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

Provide environment information

Next 12.2(-12.2.2)

Describe the Bug

I’m no longer able to import code with exports properly in Next 12.2

Expected Behavior

Next should properly bundle these files

Link to reproduction

https://github.com/hanford/12.2-exports

To Reproduce

Pull reproduction repo and try running on Next 12.2.0, you’ll see the following error: image

You can check out the working branch, which just has Next 12.1.6, after installing the older version the code will run without error.

Happy to provide more information if it’s helpful!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

We’re running into the same thing. It was working before on version 12.1.6.

Can confirm that this was working before 12.2, we use next-transpile-modules to bring in mixed modules and they worked just fine up until 12.2

add .babelrc without changing any configuration { "presets": ["next/babel"], "plugins": [] }

Nope, you can use patch-package if you want using this patch (patches/next+12.2.0.patch)

diff --git a/node_modules/next/dist/build/swc/options.js b/node_modules/next/dist/build/swc/options.js
index 4c650b2..d86fd41 100755
--- a/node_modules/next/dist/build/swc/options.js
+++ b/node_modules/next/dist/build/swc/options.js
@@ -44,7 +44,7 @@ function getBaseSWCOptions({ filename , jest , development , hasReactRefresh , g
                 baseUrl: resolvedBaseUrl,
                 paths
             } : {},
-            externalHelpers: !process.versions.pnp,
+            externalHelpers: false,
             parser: parserConfig,
             experimental: {
                 keepImportAssertions: true,

Woot, excited for the next canary! 🖤