Skip to content

Object with property '.global' is failing (globalThis) #195

@Jones-S

Description

@Jones-S

Environment

Nuxt CLI v3.0.0-27274229.29599f0
RootDir: /Users/USER/Documents/PATH
Nuxt project info:



Describe the bug

I started to migrate a nuxt 2 project to nuxt3, respectively nuxt bridge.

In a component I had a computed property looking like this:

  address() {
    return {
      address: this?.options?.global?.address || false,
      map_link: this?.options?.global?.address_map_link || false,
      phone: this.options.global.phone || false,
      phone_formatted: this.options.global.phone_formatted. || false,
    }
  },

Now when I use $ nuxi generate it will throw errors like:

_this$options$globalThis is not defined
at VueComponent.address (file://./node_modules/.cache/nuxt/nitro/index.mjs:42221:245)
at VueComponent.computedGetter [as address] (file://./node_modules/.cache/nuxt/nitro/index.mjs:13966:15)
at VueComponent.Addressvue_type_template_id_50b20264_render (file://./node_modules/.cache/nuxt/nitro/index.mjs:42190:187)
at file://./node_modules/.cache/nuxt/nitro/index.mjs:9303:25
at activateCurrentInstance (file://./node_modules/.cache/nuxt/nitro/index.mjs:9249:12)
at VueComponent.$options.render (file://./node_modules/.cache/nuxt/nitro/index.mjs:9302:16)
at VueComponent.Vue._render (file://./node_modules/.cache/nuxt/nitro/index.mjs:12795:22)
at file://./node_modules/.cache/nuxt/nitro/index.mjs:37172:69208
at eo (file://./node_modules/.cache/nuxt/nitro/index.mjs:37172:65752)
at oo (file://./node_modules/.cache/nuxt/nitro/index.mjs:37172:69184)

First I thought it was linked to the optional chaining I introduced, but I tested

address: this.options.global.address || false,

and

address: this?.options?.global?.address || false,

Both throw the same error.

When I check out the mentioned index.mjs I see this:

return {
          address: (this === null || this === void 0 ? void 0 : (_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$global = _this$options.global) === null || _this$options$global === void 0 ? void 0 : _this$options$globalThis.address) || false,

The object: _this$options$globalThis.address is problematic...

If I rewrite the line to

address: this?.options?.global?.['address'] || false, 

It works and the section in my index.mjs looks like this:

return {
          address: (this === null || this === void 0 ? void 0 : (_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$global = _this$options.global) === null || _this$options$global === void 0 ? void 0 : _this$options$global['address']) || false,

Now the object _this$options$global['address'] looks better...

I think it has to do with the case that I have an object with a key called global.

I hope my input helps. If needed I can provide further information you require.
Cheers

Reproduction

Setup a computed property with an object that contains a key global. At least this is what I expect is the reason for this problem...

https://codesandbox.io/s/purple-brook-ikqy0?file=/pages/index.vue

I tried to add a terminal to run $ nuxi generate but somehow I can't type commands in there.
I tried different browsers but no success...

image

Additional context

No response

Logs

_this$options$globalThis is not defined
  at VueComponent.address (file://./node_modules/.cache/nuxt/nitro/index.mjs:42221:245)  
  at VueComponent.computedGetter [as address] (file://./node_modules/.cache/nuxt/nitro/index.mjs:13966:15)  
  at VueComponent.Addressvue_type_template_id_50b20264_render (file://./node_modules/.cache/nuxt/nitro/index.mjs:42190:187)  
  at file://./node_modules/.cache/nuxt/nitro/index.mjs:9303:25  
  at activateCurrentInstance (file://./node_modules/.cache/nuxt/nitro/index.mjs:9249:12)  
  at VueComponent.$options.render (file://./node_modules/.cache/nuxt/nitro/index.mjs:9302:16)  
  at VueComponent.Vue._render (file://./node_modules/.cache/nuxt/nitro/index.mjs:12795:22)  
  at file://./node_modules/.cache/nuxt/nitro/index.mjs:37172:69208  
  at eo (file://./node_modules/.cache/nuxt/nitro/index.mjs:37172:65752)  
  at oo (file://./node_modules/.cache/nuxt/nitro/index.mjs:37172:69184)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bridgebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions