casbin / casbin.js

An authorization library that supports access control models like ACL, RBAC, ABAC in Frontend Javascript
https://casbin.org/docs/en/frontend
Apache License 2.0
165 stars 37 forks source link

Authorizer is not exported #261

Closed armr-dev closed 2 years ago

armr-dev commented 2 years ago

So, I just updated my Casbin.js version from 0.4.0 to 1.0.1 and I've run into the following error:

TS2305: Module '"/node_modules/casbin.js/lib"' has no exported member 'Authorizer'.

It seems that the Authorizer class is not being exported anymore. I looked into the docs (here in Github and in the Casbin website), and both still cites the Authorizer on how to use the lib.

Was the Authorizer removal by design or is this a bug?

Steps to reproduce the error

  1. Simply install any version of Casbin after the version 0.4.0;
  2. Try to import Authorizer, as noted in the docs:

    import { Authorizer } from 'casbin.js';

    or

    import * as casbinjs from 'casbin.js';
    
    const authorizer = new casbinjs.Authorizer("manual")

Environment

I was able to reproduce this error in two different scenarios:

  1. Using React with CRA
  2. Using React with Vite

This error also persisted from the version 1.0.0-beta.1, from what I tested.

casbin-bot commented 2 years ago

@Gabriel-403 @Zxilly @kingiw @nodece

hsluoyz commented 2 years ago

@nodece

GhostyJade commented 2 years ago

I've noticed the absence of the Authorizer export too when trying to upgrade from 0.4.0 to latest (in order to upgrade my project to use react-scripts@5.0.0). Without the Authorizer export I can't use the newer version with less missing polyfills, with the 0.4.0 one the project doesn't start at all.

hsluoyz commented 2 years ago

@armr-dev @GhostyJade Casbin.js v1.x has been deprecated, please use latest v0.4.1 instead: https://github.com/casbin/casbin.js/releases/tag/v0.4.1

armr-dev commented 2 years ago

This solved the issue. Thank you!