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

error Cannot read property 'silent' of undefined #564

Closed
SCWR opened this issue Oct 16, 2020 · 8 comments · Fixed by #572
Closed

error Cannot read property 'silent' of undefined #564

SCWR opened this issue Oct 16, 2020 · 8 comments · Fixed by #572

Comments

@SCWR
Copy link

SCWR commented Oct 16, 2020

I'm having a problem with it.

My project is in esm mode, so I use @vue/compostition-api esm version of the code.

I define the following code.

import {ref} from '@vue/compostition-api';
const a = ref(false);

export  function useA () {
   return {a};
}; 
...
setup(){
  const {a} = useA()
}

I got an error.
image
image

When I debugger.

vueDependency = require('vue')

let constructor = vueConstructor || vueDependency

vueConstructor is null
vueDependency is {default: ...}

Whether vueDependency should be dealt with. or use import, let babel or webpack handle it.

Or there is a problem with my project configuration.
How it needs to be configured.

@antfu
Copy link
Member

antfu commented Oct 16, 2020

Did you install the plugin via?

Vue.use(VueCompositionAPI)

@SCWR
Copy link
Author

SCWR commented Oct 16, 2020

Did you install the plugin via?

Vue.use(VueCompositionAPI)

Definitely set it up.

@antfu
Copy link
Member

antfu commented Oct 16, 2020

Can you share a minimal reproduce repo or CodeSandbox? Thanks.

@SCWR
Copy link
Author

SCWR commented Oct 16, 2020

Can you share a minimal reproduce repo or CodeSandbox? Thanks.

As I was preparing CodeSandbox, I found that I had indeed referenced the file before Vue.use(VueCompositionAPI).
And because const a s ref (false) is run first.

Therefore, mistakes will be reported.
image

The order in which ref is executed is.

export function reactive<T extends object>(obj: T): UnwrapRef<T> {

const observed = observe(obj)

const Vue = getRegisteredVueOrDefault()

Get the vue instance here.
let constructor = vueConstructor || vueDependency

Since there is no registration,
vueConstructor is null
use the default. vueDependency

setupAccessControl(observed)

function setupAccessControl(target: AnyObject): void {
if (
!isPlainObject(target) ||
isRaw(target) ||
Array.isArray(target) ||
isRef(target) ||
isComponentInstance(target) ||
accessModifiedSet.has(target)

isComponentInstance

export function isComponentInstance(obj: any) {
const Vue = getVueConstructor()
return Vue && obj instanceof Vue

The check is only verified when it is run here.

Why didn't my project run here?

I compared my project to CodeSandbox.

Discover that the vue version of that I use in my project is vue.esm.js cause of 'vueDependency' is {defalut: Vue.}.

CodeSandbox use vue.common.js
'vueDependency' is Vue.

image

I feel like there's something wrong here.

vueDependency = require('vue')

Thank you for your review.

@SCWR SCWR closed this as completed Oct 16, 2020
@LinusBorg LinusBorg reopened this Oct 16, 2020
@LinusBorg
Copy link
Member

you may have a point there with the last line. Maybe we don't properly handle he moduleinterop default export.

try {
  vueDependency = require('vue')
  if (typeof vueDependency !== 'function' && vueDependency.default) {
    vueDependency = vueDependency.default
  }
} catch {
  // not available
}

@antfu thoughts?

@antfu
Copy link
Member

antfu commented Oct 16, 2020

@LinusBorg Exactly going to do this! Is there any reason to check if it's a function, or are you meant to be check if it's Vue?

@pikax
Copy link
Member

pikax commented Oct 16, 2020

Is there any reason to check if it's a function

I think is just to make sure that vueDependency is not vue and is a module.

@LinusBorg
Copy link
Member

Yep. if its a function we already have the default export - the Vue Constructor. If it's not, we have an object with the Vue constructor in the default property

antfu added a commit that referenced this issue Oct 19, 2020
antfu added a commit that referenced this issue Oct 21, 2020
Co-authored-by: Javier Pérez <kiroushi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants