Next.js 12.0.2 + Framer 5.0.1 leading to errors in production
See original GitHub issueWhat version of Next.js are you using?
12.0.2
What version of Node.js are you using?
14.16.0
What browser are you using?
Chrome 95
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
Seeing a 500
application error when deploying app to Vercel
with the following dependencies:
next: 12.0.2
framer: 5.0.1
App deploys fine with next: 12.0.1
Vercel
error logs below:
2021-11-01T16:43:25.167Z 76a0eb5e-e736-404e-b454-15468c5f94c2 ERROR file:///var/task/node_modules/framer-motion/dist/es/context/LazyContext.mjs:1
import { createContext } from 'react';
^^^^^^^^^^^^^
SyntaxError: Named export 'createContext' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'react';
const { createContext } = pkg;
at ModuleJob._instantiate (internal/modules/esm/module_job.js:97:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:142:20)
at async Loader.import (internal/modules/esm/loader.js:182:24)
2021-11-01T16:43:25.168Z 76a0eb5e-e736-404e-b454-15468c5f94c2 ERROR file:///var/task/node_modules/framer-motion/dist/es/context/LazyContext.mjs:1
import { createContext } from 'react';
^^^^^^^^^^^^^
SyntaxError: Named export 'createContext' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'react';
const { createContext } = pkg;
at ModuleJob._instantiate (internal/modules/esm/module_job.js:97:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:142:20)
at async Loader.import (internal/modules/esm/loader.js:182:24) {
page: '/'
}
RequestId: 76a0eb5e-e736-404e-b454-15468c5f94c2 Error: Runtime exited with error: exit status 1
Runtime.ExitError
Expected Behavior
Production environment should mimic development, i.e., not crash
To Reproduce
Does not reproduce locally—only seeing on Vercel
in production
Issue Analytics
- State:
- Created 2 years ago
- Reactions:16
- Comments:37 (11 by maintainers)
Top Results From Across the Web
Next JS - SyntaxError when using framer-motion
I'm using NextJS version 12.0.3 with framer motion for animations. Putting the functionality of the framer-motion library aside, when I tag ...
Read more >Blog - Next.js 12.1
Next.js 12.1 introduces on-demand ISR, support for styled-components and Relay, zero-config Jest support, and more!
Read more >Blog - Next.js 12
We want to make every Next.js application build faster for production, and get instant feedback in local development. Next.js 12 includes a ...
Read more >Upgrade Guide - Next.js
This new parser has improved handling of CSS and now errors when invalid CSS is ... that are needed for deploying a production...
Read more >Next.js by Vercel - The React Framework
Production grade React applications that scale. The world's leading companies use Next.js by Vercel to build static and dynamic websites and web ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Downgrading to 12.0.1 worked for me too. This was a nasty bug to ship, where a site completely fails but only in production. How can this type of error be caught in the future? What tests were missing that allowed it to ship? As someone whose business depends on NextJS & Vercel, I’d love to see a retrospective on this issue to identify the gap in quality control and the mitigation steps being put in place to prevent a re-occurrence.
@KevinShiCA Regarding
@shopify/react-form
:It claims to provide a version compatible with Node.js ESM (it has an
"exports"
field that points to a .mjs file). But only most of the referenced files have the .mjs extension. The referenced file@shopify/react-form/build/esm/_virtual/_rollupPluginBabelHelpers.js
doesn’t have the correct extension, so Node.js doesn’t treat it as ESM. That leads to this error:This should be fixed in the
@shopify/react-form
package. Please report it there. cc @michenlyimport { createContext } from 'react'
is fine instead, if it’s really react that is installed here. I have seen reports where react has been replaced with preact and that caused this error. @developit is working on that. If this is not related to preact, please provide a reproduction @sambeckerPS: Please try
experimental.esmExternals: false
as workaround.