1

I'm implementing node-casbin in my project. I tried importing everything into my project using the code below.

import * as casbin from 'casbin';

When I save my Node.js server crashes with the error below.

import * as casbin from 'casbin';
       ^

SyntaxError: Unexpected token *
jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
CloudBranch
  • 1,434
  • 3
  • 18
  • 23
  • possible duplicate: https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import/39436580 TL;DR your node version may not (fully) support `import`. Have you tried using `require`? – Damon Sep 16 '19 at 15:15
  • @Damon What version supports ES 2015? I'm using v10.16.0. – CloudBranch Sep 16 '19 at 15:19
  • 1
    Even Node 12 still requires an opt in via the `--experimental-modules` flag. https://nodejs.org/api/esm.html#esm_enabling Your node version supports most ES features (see https://node.green/), just not ES modules unless you use the flag and follow the setup. This answer has a good summary of some of the gory details: https://stackoverflow.com/questions/37132031/nodejs-plans-to-support-import-export-es6-es2015-modules – Damon Sep 16 '19 at 15:44
  • 1
    Your best bet would be to do `const casbin = require('casbin')` unless you feel a strong existential need to use ESM over CJS in which case you will probably have to do more configuration to get a possibly working result... – Damon Sep 16 '19 at 15:47
  • Please send a GitHub issue – hsluoyz Oct 01 '19 at 06:08

0 Answers0