j0j00 / flutter_liquidcore

Node.js virtual machine for Android and iOS in Flutter.
https://pub.dev/packages/flutter_liquidcore
BSD 2-Clause "Simplified" License
67 stars 16 forks source link

require or import not supported #19

Closed bradcroteau closed 3 years ago

bradcroteau commented 4 years ago

Using flutter_liquidcore code like the following returns errors: ReferenceError: require is not defined; or ReferenceError: import is not defined.

if (_jsContext == null) { _jsContext = new JSContext(); String code = """ const API = require('./local-api/index.js')(); API.login("${aEmail}", "${aPassword}").then((output) => { API.Stats("${userTag}", "${platform}").then((output) => { console.log(output); }).catch((err) => { console.log(err); }); }).catch((err) => { console.log(err); }); """;

Being a node.js environment and not being able to break my javascript out of that _jsContext bubble to reference other .js files seems important for the utility of flutter_liquidcore.

j0j00 commented 3 years ago

You should read up on the original library's documentation.

If you want to use things like "require" or "import"s on local files, then you need to bundle it up, then use a microservice.

The jscontext is for simple JavaScript evaluations. It doesn't do any file management type stuff.