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.

Use require syntax for docs as an example instead of import

See original GitHub issue

I 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');

image 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 ; image

Since this is casbin implementation for nodejs I would recommend to make example specific to node developers.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Zxillycommented, Mar 14, 2021

@hsluoyz In fact, I believe it should work as expected. I’m resolving problem.

1reaction
hsluoyzcommented, Mar 14, 2021

@Zxilly what is import { newEnforcer } from 'casbin'; for? Browser? We should also provide the code for Node.js definitely.

Read more comments on GitHub >

github_iconTop 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 >

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