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] Call typeof in template return Reference Error #23

Open
dimar-hanung opened this issue Nov 13, 2021 · 2 comments
Open

[Bug] Call typeof in template return Reference Error #23

dimar-hanung opened this issue Nov 13, 2021 · 2 comments
Labels
bug Something isn't working contribution welcome Good for newcomers has workaround Priority: P4

Comments

@dimar-hanung
Copy link

Version

image

What is expected?

Can call typeof in template

What is actually happening?

Return ReferenceError: _typeof is not defined

Steps to Reproduce

  1. Set config following docs
    image
  2. Call typeof for debugging in template
    image
  3. This error appear in console, and page doesn't load because this error
    image
@JuniorTour
Copy link
Owner

JuniorTour commented Nov 13, 2021

It is a bug when working with vue-cli.


Workaround

1. Exclude @babel/plugin-transform-typeof-symbol from @vue/cli-plugin-babel/preset

// babel.config.js
module.exports = {
    presets: [
        [
            '@vue/cli-plugin-babel/preset',
            {
                exclude: [
                    '@babel/plugin-transform-typeof-symbol'
                ]
            }
        ]
    ],
}

2. Only exclude result of this compiler

// babel.config.js
module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ],
  exclude: 'VueTemplateBabelCompiler'
}

This compiler take the @vue/cli-plugin-babel/preset as a babel preset by default.

So the typeof keyword is transformed into:

var _typeof = require(".../node_modules/@babel/runtime/helpers/typeof")

// your code...
_typeof example

It is unexpected.

May be we can ignore the default babel.config.js of vue-cli.


Do you have interest to fix this issue?
You can:

  1. Try to reproduce this code snippet and error by setup DEMO Project.

  2. Follow CONTRIBUTING.md to make a Pull Request.

@JuniorTour JuniorTour added bug Something isn't working contribution welcome Good for newcomers and removed need triage labels Nov 13, 2021
@dimar-hanung
Copy link
Author

Thanks for solution and explanation , it's work after exclude '@babel/plugin-transform-typeof-symbol'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contribution welcome Good for newcomers has workaround Priority: P4
Projects
None yet
Development

No branches or pull requests

2 participants