nuxt: Cannot include @nuxt/babel-preset-app in nuxt.config.js

Version

v2.4.0

Reproduction link

https://codesandbox.io/s/q91mz897jq

Steps to reproduce

Include nuxt babel preset as described in docs: https://nuxtjs.org/api/configuration-build#babel

What is expected ?

Page loads correctly

What is actually happening?

Page doesnt load and shows a regeneratorRuntime is not defined error

Additional comments?

Related: https://github.com/nuxt/nuxt.js/issues/4873#issuecomment-458741553

<div align="right">This bug report is available on Nuxt community (#c8574)</div>

About this issue

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

Most upvoted comments

This issue is due to @nuxt/babel-preset-app is specified without any target.

presets: ["@nuxt/babel-preset-app"] is the default preset with specified target in nuxt.

But what happened in https://github.com/nuxt/nuxt.js/issues/4873#issuecomment-458722702 mentioned by @mauxtin is a different issue that nuxt doesn’t support different babel config in server and client.

For now, I suggest using default babel preset provided by Nuxt, you can still add other configs(like: build.babel.plugins).

Or you can use functional preset:

build: {
  babel: {
    presets({ isServer }) {
      const targets = isServer ? { node: 'current' } : { ie: 11 }
      return [
        [ require.resolve('@nuxt/babel-preset-app'), { targets } ]
      ]
    }
  }
}

The server and client babel config can be a new feature request, I think we can introduce build.babel.client and build.babel.server with same config as build.babel, like:

build: {
  babel: {
    client: {
      presets: [...],
      plugins: [...]
    }
    server: {
      presets: [...]
    }
  }
}

How do you think @pimlie @LuXDAmore @mauxtin ? If you have any proposal, please comment here.

I think the “buildTarget” is missing.

build: {
  babel: {
    presets({ isServer }) {
      const targets = isServer ? { node: 'current' } : { ie: 11 }
      return [
        [
          require.resolve('@nuxt/babel-preset-app'),
          {
            buildTarget: isServer ? 'server' : 'client',
            targets
          }
        ]
      ]
    }
  }
}

It works.

@pimlie Good point! Will link the PR here as soon as it’s there. I’ll do some doc work today 😉

@pimlie Sorry, it’s my typo, should be targets, I’ve updated the comment. image

Indeed, I’ll update the doc for function preset part

@mauxtin No, because you don’t set the targets.

Nuxt’s default preset is set up by default as the name suggests 😋