Nuxt.js: The instanceof operator in the dev mode does not work.

Created on 19 Apr 2019  路  6Comments  路  Source: nuxt/nuxt.js

Version

v2.5.1

Reproduction link

https://github.com/archieDeveloper/nuxt-bug

Steps to reproduce

npm install
npm run dev

go to main page to website.
check the console.

What is expected ?

in the console inscription [object Error] true Request failed with status code 404

What is actually happening?

in the console inscription [object Error] false Request failed with status code 404

Additional comments?

Environment

Linux Ubuntu 18.04
npm version 6.7.0
node version v11.12.0

Dependencies package.json

"@nuxtjs/axios": "^5.4.1"
"nuxt": "^2.5.1"

Code in the page component

async asyncData ({ $axios }) {
    const toString = {}.toString;
    try {
        await $axios.get('https://google.com/test'); // should return 404 error
    } catch (error) {
        // expected - [object Error] true Request failed with status code 404
        // we get - [object Error] false Request failed with status code 404
        console.log(toString.call(error), error instanceof Error, error);
    }
}

When an http error occurs, the $axios module throws an exception and translates the code into the catch branch. An object of type Error falls into the error variable, but the instanceof operator shows the opposite. Also error instanceof Object returns false in the result.

This behavior is observed only when the npm run dev application is running. When running npm run build npm run start works correctly.

This bug report is available on Nuxt community (#c9081)
bug-report stale

Most helpful comment

Apparently nothing has been done on this so.. just bumping this to show it's still an issue

All 6 comments

I also encountered the same problem锛寃hen i use code:
new Date() instanceof Date
In the dev mode:
It return false
in the prod mode:
It return true

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

Apparently nothing has been done on this so.. just bumping this to show it's still an issue

Confirmed this is still an issue... in dev mode, any prop with type: Date will throw console warnings in dev mode. Because new Date() instance of Date returns false.

eg. using Buefy DatePicker, I see this:

core_1           | [Vue warn]: Invalid prop: type check failed for prop "selectedDate". Expected Date, Array, got Date 
core_1           | 
core_1           | found in
core_1           | 
core_1           | ---> <BDatepickerTableRow>
core_1           |        <BDatepickerTable>
core_1           |          <BDropdownItem>
core_1           |            <BDropdown>
core_1           |              <BDatepicker>

My workaround is to only populate the value after the component is mounted, which is a pain.

This bug is still relevant with today's version of nuxt and nuxt-edge. You can still install @archieDeveloper 's project and reproduce the bug today!

I'm unable to use https://github.com/typestack/class-validator on my Nuxt project in dev mode, because it uses instanceof internally (for Arrays, Sets, Maps, Objects...)

The only workaround I found is to write the following in nuxt.config.js:

  render: {
    bundleRenderer: {
      runInNewContext: false,
    },
  },

@MaximeCouasnon , fine this works for me!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maicong picture maicong  路  3Comments

danieloprado picture danieloprado  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

mikekidder picture mikekidder  路  3Comments