how can I import external js modules
andrew2015 opened this issue · 8 comments
does system design support to import js modules from npmjs repo and call it in behavior?
As shown in the example here, in Electron version of the app you can import core node libraries and test it right away in System Designer.
For modules from npm, you can require it normally in behaviors, but you can not test it with System Designer. You will need to export the system in Node.js format and follow these steps of the documentation:
- Install System Runtime:
npm install system-runtime
- Install the library you want to use:
npm install moment
- Execute your file:
node mysystem.js
I will update the documentation to explain how to use a npm module.
When I export my system to Node and run it as per these instructions, I get the following error: "runtime: error when calling the action 'render' on component 'page-html' (HTMLComponent class): document is not defined". This occurs for every reference to 'document'.
This error does not occur in System Designer.
Am I missing something?
It does not work because the system you run with node contains a reference to document
(see https://developer.mozilla.org/en-US/docs/Web/API/document) which is not managed by Node.js.
It works in System Designer because the system is executed in a browser (Chromium for the desktop version to be more precise), so you have access to document
.
I will update the documentation to add this missing information.
I'm trying the exact example you provide in test-a-server-side-application and I'm getting the following error:
error: error when calling the action 'start' on component 'be94220d-f394-4dec-8532-0a05401cef76' (_System class): require is not defined
I don't understand what I'm missing here...
Do you have the latest version of System Designer (v5.2.0) ?
There was an issue with node API in older versions.