Skip to content

fix(babel-preset-app): always transpile optional chaining and nullish-coalescing for server #8203

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

Merged
merged 4 commits into from
Oct 14, 2020

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Oct 14, 2020

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Since node@14 supports optional chaining, @babel/preset-env disables transpilation for this target (we use runtime node version as target). But this makes troubles (#7722) as webpack@4 uses acorn 6.x which doesn't support this syntax (webpack/webpack#10227)

Alternative

We could strictly set node target to 8 or 10 to avoid same happening in the future with acorn and nuxt@2

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

Sorry, something went wrong.

@pi0 pi0 requested a review from clarkdo October 14, 2020 12:36
Copy link
Member

@clarkdo clarkdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding this plugin in babel-preset-app only for server env would be better.

@pi0
Copy link
Member Author

pi0 commented Oct 14, 2020

@clarkdo Indeed but as mentioned i tried this: (on an external project)

image

This doesn't works (probably preset-env somehow takes over?)

And what do you think about fixing target to 10 or 12?

@clarkdo
Copy link
Member

clarkdo commented Oct 14, 2020

@pi0 What about add it in include of preset-env ? I can take a look tonight if it doesn't work.

include: ['proposal-optional-chaining']

@pi0
Copy link
Member Author

pi0 commented Oct 14, 2020

@clarkdo Actually it was babel cache that needed to be manually invalidated 🙈 Seems all fine now

@pi0 pi0 requested a review from clarkdo October 14, 2020 13:43
clarkdo
clarkdo previously approved these changes Oct 14, 2020
Copy link
Member

@clarkdo clarkdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@pi0 pi0 changed the title fix: transpile optional chaining by default fix: always transpile optional chaining and nullish-coalescing for server Oct 14, 2020
@pi0 pi0 changed the title fix: always transpile optional chaining and nullish-coalescing for server fix(babel-preset-app): always transpile optional chaining and nullish-coalescing for server Oct 14, 2020
@pi0 pi0 merged commit c75ac80 into dev Oct 14, 2020
@pi0 pi0 mentioned this pull request Oct 14, 2020
@TheAlexLichter TheAlexLichter deleted the fix/optional-chain branch October 14, 2020 15:16
@marcvangend
Copy link

marcvangend commented Nov 18, 2020

I'm running nuxt 2.14.7 now (with node 15.1.0, yarn 1.2.10), but I'm still getting a fatal error when I try to use a nullish coalescing operator or optional chaining in a generate function in my nuxt.config.js:

 FATAL  Invalid or unexpected token                                                                      15:20:32

  const foo = data?.foo ?? 'bar'
  ^
  
  SyntaxError: Invalid or unexpected token
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)


   ╭──────────────────────────────────────────────╮
   │                                              │
   │   ✖ Nuxt Fatal Error                         │
   │                                              │
   │   SyntaxError: Invalid or unexpected token   │
   │                                              │
   ╰──────────────────────────────────────────────╯

Is this expected behavior? Am I making a mistake somewhere? Should I open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants