Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

how can I import external js modules #137

Open
andrew2015 opened this issue Sep 26, 2020 · 8 comments
Open

how can I import external js modules #137

andrew2015 opened this issue Sep 26, 2020 · 8 comments
Labels

Comments

@andrew2015
Copy link

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

@ecarriou
Copy link
Member

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
Copy link

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
Copy link
Member

ecarriou commented Mar 2, 2022

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
Copy link

tjerkherckenrath commented Mar 3, 2022 via email

@tjerkherckenrath
Copy link

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
Copy link
Member

ecarriou commented Apr 12, 2022

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

@tjerkherckenrath
Copy link

tjerkherckenrath commented Apr 12, 2022 via email

@tjerkherckenrath
Copy link

tjerkherckenrath commented Apr 12, 2022 via email

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants