design-first / system-designer

A low-code development platform for creating systems πŸ‡ΊπŸ‡¦#standwithUkraine
https://designfirst.io/systemdesigner/
Apache License 2.0
930 stars 136 forks source link

how can I import external js modules #137

Open andrew2015 opened 3 years ago

andrew2015 commented 3 years ago

does system design support to import js modules from npmjs repo and call it in behavior?

ecarriou commented 3 years ago

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:

  1. Install System Runtime:

npm install system-runtime

  1. Install the library you want to use:

npm install moment

  1. Execute your file:

node mysystem.js

I will update the documentation to explain how to use a npm module.

tjerkherckenrath commented 2 years ago

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?

ecarriou commented 2 years ago

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.

tjerkherckenrath commented 2 years ago

That makes sense, thank you.

Tjerk

On Wed., Mar. 2, 2022, 6:03 p.m. Erwan Carriou, @.***> wrote:

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.

β€” Reply to this email directly, view it on GitHub https://github.com/design-first/system-designer/issues/137#issuecomment-1057479108, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXORIMSRBZ7ZD7DGU6SQFS3U57XUVANCNFSM4R2XKUMQ . You are receiving this because you commented.Message ID: @.***>

tjerkherckenrath commented 2 years ago

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

ecarriou commented 2 years ago

Do you have the latest version of System Designer (v5.2.0) ? There was an issue with node API in older versions.

tjerkherckenrath commented 2 years ago

Hmm, I haven't checked the version, I'll make sure it's up to date and I'll try again.

Thanks, Tjerk

On Tue., Apr. 12, 2022, 1:37 p.m. Erwan Carriou, @.***> wrote:

Did you have the last version of System Designer (v5.2.0) ?

β€” Reply to this email directly, view it on GitHub https://github.com/design-first/system-designer/issues/137#issuecomment-1097005821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXORIMSNQDIMVBBIE7TPBYTVEWYGPANCNFSM4R2XKUMQ . You are receiving this because you commented.Message ID: @.***>

tjerkherckenrath commented 2 years ago

My version was out of date...

I'll have to remember to check for new versions πŸ˜€

Finally off to the races!

Thank you πŸ™ Tjerk

On Tue., Apr. 12, 2022, 1:37 p.m. Erwan Carriou, @.***> wrote:

Did you have the last version of System Designer (v5.2.0) ?

β€” Reply to this email directly, view it on GitHub https://github.com/design-first/system-designer/issues/137#issuecomment-1097005821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXORIMSNQDIMVBBIE7TPBYTVEWYGPANCNFSM4R2XKUMQ . You are receiving this because you commented.Message ID: @.***>