question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple warnings and errors during configuration

See original GitHub issue

Hi!

I’m using Vue 2.5.2, and this is an existing and stable application I’m hoping to improve with CASL.

So far, nothing I’ve tried works, and that includes the import ability from './ability' which gave me errors:

Module not found: Error: Can’t resolve ‘./ability’

I switched to: import ability from '@casl/ability' which gives me the following warnings:

[casl]: Ability contains only inverted rules. That means user will not be able to do any actions. This will be changed to Error throw in the next major version

"export ‘default’ (imported as ‘ability’) was not found in ‘@casl/ability

… and the errors:

[Vue warn]: Property or method “$can” is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

[Vue warn]: Error in render: “TypeError: _vm.$can is not a function”

TypeError: _vm.$can is not a function

In the “main.js” file, I have:

import ability from '@casl/ability'

new Vue({
  el: '#app',
  router,
  store,
  ability,
  template: '<App/>',
  components: { App }
})

In the "App.vue file, I have:

<template>
	<router-link v-if="$can('read', 'Team')" to="/teams" class="navbar-item">
		Teams
	</router-link>
</template>

import { AbilityBuilder } from '@casl/ability'

export default {
    name: 'App',
    ability: AbilityBuilder.define((can, cannot) => {
      switch (this.userGroupID) {
        case 1:
          break
        case 2:
          break
        case 3:
          break
        case 4:
          cannot('read', 'Team')
          break
      }
    }),...

I’m assuming this is how I use the this.userGroupID parameter, but I have no idea if it is working or not, given the multiple warnings and errors, and I have no idea what to do with ability, since there’s no guidance in the documentation, in the context of Vue.

I tried using the Can package, but that created more warnings and errors, so I had to abandon that.

Some assistance would be much appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
OctaneInteractivecommented, Jul 10, 2019

I looked at the example but it’s far too complicated to understand — for instance, the example deviates from the documentation in how ability is imported (in the example, it’s in a “*.js” file), and it doesn’t explain how the user ID (or other parameters) are passed into the ability object.

Yes, I’ve read both of those documents, but — as I said — the example deviates from the documentation, and it’s far too complex.

What would make far more sense, would be to provide a basic minimum configuration that matches the documentation.

Also, you haven’t explained the reasons for the multiple errors on the initial import; I removed the code from the Vue component, to isolate the errors, and the import isn’t working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Too many errors and warning in Event Viewer!!!
All drivers and firmware are updated, all app from Store too. There 're too many errors and warnings in Event viewer (img). Errors:...
Read more >
Configuration error and warning messages - IBM
Configuration error and warning messages. A non-zero return code value between 1 and 999 is a warning. Warning messages do not prevent a...
Read more >
0.11 — Configuring your compiler: Warning and error levels
C++ does not support an official way to do this, but many ... To treat warnings as errors, right click on your project...
Read more >
How to tell Visual Studio not to display the same warning ...
The warning message might be appropriate. Sounds like you use the source code file in more than one project. Look at the Output...
Read more >
Warnings and Errors in Local - Local WP
There are two reasons why Local looks broken compared to the remote site: ... PHP can be configured to display a wide spectrum...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found