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

Adding @babel/preset-env cause error #2722

Closed
marialovesbeans opened this issue Mar 27, 2021 · 2 comments · Fixed by #2766
Closed

Adding @babel/preset-env cause error #2722

marialovesbeans opened this issue Mar 27, 2021 · 2 comments · Fixed by #2766

Comments

@marialovesbeans
Copy link

marialovesbeans commented Mar 27, 2021

In my case, I'm trying to add Jest for unit testing. Jest needs to transpile the unit test code to ES5 before running it, because there're some ESNext syntax node.js does not understand, such as nullish assignment operator ?=.

However, I'm sure there're tons of other scenarios adding @babel/preset-env is necessary, so it's impactful to have this bug fixed.

Step 1) yarn add @babel/preset-env

Step 2) Add to package.json:

"babel": {
    "presets": [
      "@babel/preset-env"
    ]
 },

Result:
Launch website at http://localhost:3000, the webpage crashes, logging error in the browser: Uncaught SyntaxError: The requested module '/src/App.jsx' does not provide an export named 'default'

Why does adding this cause such an error? How can I fix this?

@github-actions
Copy link

Hello @marialovesbeans. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by need reproduction will be closed if no activities in 3 days.

@marialovesbeans
Copy link
Author

I'm not sure if this is reproducible on codesandbox as this is the building process. But any vitejs project adding this in the package.json will fail:

"babel": {
    "presets": [
      "@babel/preset-env"
    ]
 },

underfin added a commit that referenced this issue Mar 29, 2021
@underfin underfin mentioned this issue Mar 29, 2021
9 tasks
@anncwb anncwb added the has pr label Mar 30, 2021
yyx990803 pushed a commit that referenced this issue Mar 31, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants