Throws ERROR Unexpected token import
See original GitHub issueHi, I am trying the example given in node-casbin readme and facing following error.
error: uncaughtException: Unexpected token import
/server/services/casbin.service.js:1
(function (exports, require, module, __filename, __dirname) { import * as casbin from 'casbin';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/server/routers/casbin.routes.js:3:21)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/server/routers/app.routes.js:95:24)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Node.js - SyntaxError: Unexpected token import - Stack Overflow
Use transpiler like Babel to use import in Nodejs as it is not natively supported in nodejs.There is best alternative of import is...
Read more >SyntaxError: Unexpected token import in Node.js | bobbyhadz
The "SyntaxError: Unexpected token import" occurs when we use the ES6 import syntax in a version of Node that doesn't support it. To...
Read more >Error Unexpected token import in nodejs | Edureka Community
SyntaxError : Unexpected token import at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:387:25) at Object.Module.
Read more >Unexpected token import when importing a module written ...
Issue description or question When importing a module written with es6 imports, I get the error message Unexpected token import Quokka.js ...
Read more >Unexpected token import Node.js - Reactgo
To fix this error, we can use the commonjs modules require() function and module.exports instead of es6 modules. app.js. const express = require ......
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 Free
Top 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
Thanks, @akshay27395 I tried it and it worked…!
I tried the above solution but it leads me to a new error as below.