Use require syntax for docs as an example instead of import
See original GitHub issueI would like to point out that while following the examples I faced following error : -
In server.js
import { newEnforcer } from 'casbin';
const enforcer = await newEnforcer('basic_model.conf', 'basic_policy.csv');
This is because nodejs natively supports require syntax
and the index file of the librar is not in form of a module.
Adding "type": "module"
in package.json (which parses every js file as a module) solves the issue but then messes with other packages like express.js
Additionally on declaring following
const enforcer = await newEnforcer('basic_model.conf', 'basic_policy.csv')
I got this error ;
Since this is casbin implementation for nodejs I would recommend to make example specific to node developers.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Using Node.js require vs. ES6 import/export - Stack Overflow
See when we require the component in asynchronous way, then we use import it in some async manner as in const variable using...
Read more >JavaScript require vs import - Flexiple
Syntax, explanation, example and differences between JavaScript require and import statements and other related concepts.
Read more >Using import and require in the same file - Node JS - YouTube
Found solution here: https://www.kindacode.com/article/node-js-how-to- use - import -and- require -in-the-same-file/
Read more >import - JavaScript - MDN Web Docs - Mozilla
To load modules in non-module contexts, use the dynamic import syntax instead. import declarations are designed to be syntactically rigid (for ...
Read more >The Huge Difference Between ES6 import and ES5 require in ...
Here's an example using require that we're going to refactor to be more performant using modern JavaScript syntax (ES6 import syntax).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hsluoyz In fact, I believe it should work as expected. I’m resolving problem.
@Zxilly what is
import { newEnforcer } from 'casbin';
for? Browser? We should also provide the code for Node.js definitely.