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

[BUG] 5.0 Failed to compile with create-react-app #1307

Closed
semihraifgurel opened this issue Oct 27, 2021 · 48 comments
Closed

[BUG] 5.0 Failed to compile with create-react-app #1307

semihraifgurel opened this issue Oct 27, 2021 · 48 comments
Labels
bug Something isn't working

Comments

@semihraifgurel
Copy link

Failed to compile.

./node_modules/framer-motion/dist/es/components/AnimatePresence/index.mjs
Can't import the named export 'Children' from non EcmaScript module (only default export is available)
@semihraifgurel semihraifgurel added the bug Something isn't working label Oct 27, 2021
@loganpowell
Copy link

Got the same exact problem here! I think it's the .mjs extension (unsupported by typescript with CRA)

@mattgperry
Copy link
Collaborator

mattgperry commented Oct 28, 2021

https://www.framer.com/docs/guide-upgrade/#%23esm-and-create-react-app
facebook/create-react-app#10356

We are looking at a fix but it might be in CRA. Let’s track it in this ticket

@Kripu77
Copy link

Kripu77 commented Oct 28, 2021

Having same issue

@mattgperry mattgperry changed the title [BUG] Version 5.0.0 Failed to compile [BUG] 5.0 Failed to compile with create-react-app Oct 28, 2021
@yozi-developer
Copy link

I was able to fix it by patching CRA
formatjs/formatjs#1395 (comment)

@jwfwessels
Copy link
Contributor

After testing a bit it seems that the issue is with how CRA handles ESM dependencies and more particularly transitive dependencies are not handled correctly it seems. There is also an outstanding issue with CRA about this facebook/create-react-app#10356.

Options:

  1. This is 'fixed'/doesn't break in the next version of CRA which you can try today (Create React App 5 Alpha facebook/create-react-app#11278)
    take note though its still in alpha.

  2. You can patch CRA to get around the issue as described in a number of tickets from other libraries

@AndreaEsposit
Copy link

AndreaEsposit commented Oct 28, 2021

So as of now, the only solution to even be able to use framer-motion is to temper with CRA(if you are using CRA)?. Thant's a bummer, means that I can't use this library.

@loganpowell
Copy link

Thank you guys for looking into this! @jwfwessels have you tried CRA5?

@mattgperry
Copy link
Collaborator

@AndreaEsposit You can still use 4.1.17, you just won't get the drag-to-reorder components.

@yozi-developer
Copy link

yozi-developer commented Oct 28, 2021

BTW: the issue exists with Storybook@6.3.12 too, can be overcome using webpackFinal and #1307 (comment)

@Wa-lead
Copy link

Wa-lead commented Oct 29, 2021

Having the same issue here.

@justrealmilk
Copy link

Tried to configure a work around using CRACO and failed soooo back to 4.*

@dcakmak
Copy link

dcakmak commented Oct 29, 2021

my setup as asked, was just a fresh project setup:
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"framer-motion": "^5.0.0"
"node-sass": "^6.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"styled-components": "^5.3.3",
"web-vitals": "^1.1.2"

@jafin
Copy link

jafin commented Nov 1, 2021

@justrealmilk I added the following to craco.config.js and it appears to work.

module.exports = {
  webpack: {
        configure: {
            module: {
                rules: [
                    {
                        type: 'javascript/auto',
                        test: /\.mjs$/,
                        include: /node_modules/,
                    },
                ],
            },
        },
    },
}

@frabcus
Copy link

frabcus commented Nov 1, 2021

I get the same error using this via Next.js

@kpjob555
Copy link

kpjob555 commented Nov 2, 2021

I also have this same issue

@yadprab
Copy link

yadprab commented Nov 2, 2021

me too facing the same

@titan3755
Copy link

same problem. Is there no way to fix it without downgrading framer-motion?

@justrealmilk
Copy link

@justrealmilk I added the following to craco.config.js and it appears to work.

module.exports = {

  webpack: {

        configure: {

            module: {

                rules: [

                    {

                        type: 'javascript/auto',

                        test: /\.mjs$/,

                        include: /node_modules/,

                    },

                ],

            },

        },

    },

}

Weirdly didn't work for me

@Solo-Digital
Copy link

@justrealmilk I added the following to craco.config.js and it appears to work.

module.exports = {

  webpack: {

        configure: {

            module: {

                rules: [

                    {

                        type: 'javascript/auto',

                        test: /\.mjs$/,

                        include: /node_modules/,

                    },

                ],

            },

        },

    },

}

Weirdly didn't work for me

It worked for me

@daxaxelrod
Copy link

@Solo-Digital Did you already have craco installed?

@Solo-Digital
Copy link

@Solo-Digital Did you already have craco installed?

Yes - Craco version 6.3.0 and Framer Motion 5.2.0

@wahidshafique
Copy link

I am getting this error when trying to run storybook 6.3.12 and framer 5.2.1

@j-borg
Copy link

j-borg commented Nov 9, 2021

I am getting this error when trying to run storybook 6.3.12 and framer 5.2.1

Same here when running a Storybook build. @jafin 's solution worked for us though. Added the mjs rule to the webpackFinal config in Storybook https://storybook.js.org/docs/react/configure/webpack#extending-storybooks-webpack-config

karrui added a commit to opengovsg/FormSG that referenced this issue Dec 10, 2021
karrui added a commit to opengovsg/FormSG that referenced this issue Dec 13, 2021
…book) (#3168)

* chore: run `npx npm-check-updates -u` to update all packages to latest

except eslint, since we are still locked to v7 until cra supports it

* lint: run lint fix

* fix: allow framer-motion v5 to be used with CRA

see framer/motion#1307

* fix: type breaking change in msw 0.36.0

see https://github.com/mswjs/msw/releases/tag/v0.36.0

* fix: rhf regression where last ref is focused instead of first

need to now only assign first ref in array-like fields such as Rating field with options, or radio fields.

* fix(TableFieldStories): type error

* fix(Radio): infinite loop/crash on dependent radio input

this was introduced in 7.14 or earlier (did not go back further to check). Suspect infinite validation loop.

no clue on why it happens, just that it happens, unfortunately. However, seems to be fixed by adding dependent validation, a new feature in 7.14.

* feat(Checkbox): use dependent field validation introduced in rhf7.14

* fix(PublicFormPageStory): add chromatic.pauseAnimationAtEnd prop

prevent animation from hiding start page title
@itjustbong
Copy link

i have same issue with my CRA and i got solution from
link

@mattgperry
Copy link
Collaborator

I believe this will fix CRA https://github.com/facebook/create-react-app/releases/tag/v5.0.0

@semihraifgurel
Copy link
Author

Working with CRA 5

@bkiac
Copy link

bkiac commented Jan 25, 2022

I still have this issue with @chakra-ui/react@1.7.3, framer-motion@5.6.0, storybook-react@6.4.14 and @chakra-ui/storybook-addon@1.0.1

@sgarcia-dev
Copy link

Having this issue on a Webpack v4.43.x (no CRA) install, none of the fixes appear to work besides downgrading to v4.1.x . Perhaps we shouldn't close this issue until a new version of framer-motion arrives which solves this issue without requiring patches/updates to other tooling?

@bluekingnfx
Copy link

Update your react scripts, npm install react-scripts@latest

@sgarcia-dev
Copy link

We aren't using react-scripts @bluekingnfx

@isc30
Copy link

isc30 commented Mar 5, 2022

this fixes it:

    webpackConfig.module.rules.push({
      test: /\.mjs$/,
      include: /node_modules/,
      type: 'javascript/auto',
    })
    webpackConfig.resolve.extensions.push('.mjs')

clean-teach added a commit to clean-teach/study-nomadcoders-react-masterclass-animations that referenced this issue Dec 16, 2022
# ****#8.0 Introduction****

## 개요

- 이번 섹션에서는 Framer Motion을 써서 애니메이션을 만드는 법에 대해 학습한다.

## Framer Motion

[Production-Ready Animation Library for React | Framer Motion](https://www.framer.com/motion/)

- `ReactJS` 용 라이브러리
- 애니메이션을 쉽게 만들 수 있다.
- Pose 라는 라이브러리에서 시작됐다.
- [Framer](https://www.framer.com/)는 디자이너를 위해 프로토타입을 만들어주는 회사이다.
    - Framer Motion 라이브러리는 Framer에서 만들었다.

# ****#8.1 Installation****

## 목표

- 프로젝트에 Framer Motion 을 설치해본다.
- Framer Motion 을 사용해서 애니메이션을 만들어 본다.

## 사용법

[Introduction | Framer for Developers](https://www.framer.com/docs/introduction/#quick-start)

1. `npm install framer-motion` 설치
    - create-react-app Version 4 이하에서는 에러가 발생 할 것이다.

        → [Ecma Script Module 을 허용해야 한다.](https://www.notion.so/08-ANIMATIONS-d7c84838163c42e9980adba335f04f14)

        - create-react-app Version 5에서는 Ecma Script Module를 허용하기 때문에 해당 에러가 발생하지 않는다.
2. `import { motion } from "framer-motion"` 불러오기
3. `[<motion.div />` 컴포넌트](https://www.framer.com/docs/introduction/##the-motion-component)
    - Framer Motion 을 사용하기 위해서 일반 HTML Element를 사용 할 수는 없다.

        → Framer Motion이 제공하는 `motion` 패키지를 통해서 컴포넌트를 생성 한다.

### `[craco](https://github.com/dilanx/craco)`

- create-react-app 의 설정사항을 **O**verride(무시) 해주는 라이브러리
- 사용법
    1. `npm i -D @craco/craco` 설치
    2. `craco.config.js` 파일 생성
        - `package.json` 과 같은 단계에 위치
    3. 해당 파일 설정이 필요한 곳에서 제공하는 문서를 따라서 `craco.config.js` 작성
        - 예 : [framer/motion#1307 (comment)
    4. `package.json` 의 script 명령어 수정

        ```json
        "scripts": {
        ~~-  "start": "react-scripts start"~~
        **+  "start": "craco start"**
        ~~-  "build": "react-scripts build"~~
        **+  "build": "craco build"**
        ~~-  "test": "react-scripts test"~~
        **+  "test": "craco test"**
        }
        ```
@channyeintun
Copy link

this fixes it:

    webpackConfig.module.rules.push({
      test: /\.mjs$/,
      include: /node_modules/,
      type: 'javascript/auto',
    })
    webpackConfig.resolve.extensions.push('.mjs')

Thanks. This solves my problem in nextjs project.

@thesmashten
Copy link

Lol I broke my entire project trying to add framer-motion. My advice: don't bother. Get good at CSS animations, the clowns at framer motion have no clue what they're doing and their stuff only works in their perfect little sandbox display online.

@isc30
Copy link

isc30 commented Jan 17, 2024

@thesmashten framer-motion is an awesome project and follows the latest standards in ESM. If you can't get it to run, look at yourself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests