retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.06k stars 652 forks source link

es6 target #237

Closed mikecowgill closed 5 years ago

mikecowgill commented 5 years ago

I have a problem using the 1.0.0 release with my angular project. Once I updated to 1.0.0 and error showed up on the constructor when calling super('component') for a custom component. The error is: Class constructor Component$1 cannot be invoked without 'new'

After some research it seems to be due to rete targeting es6 now. While I tried also updating my angular project to target es6, there are some dependencies preventing me. I'm only able to target es5.

Is there a necessity to target es6 with rete? Or if you know of any other ways to resolve this, help is much appreciated.

If I revert to 1.0.0-beta.5 everything works fine.

Ni55aN commented 5 years ago

I found solution:

Add this to tsconfig.json

 "include": [
    "src/**/*.ts",
    "node_modules/rete/build/*.js"
  ]
Ni55aN commented 5 years ago

There is problem when transpile to es5.

[...his.inputs.values(), ...this.outputs.values()] must be [].concat(g(this.inputs.values()),g(this.outputs.values())), but TS give the this.inputs.values().concat(this.outputs.values());.

So the error this.inputs.values(...).concat is not a function appears

mikecowgill commented 5 years ago

I haven't been able to get retejs running with es5 now either. Instead I've updated my project to transpile to es6 and found a workaround for the other dependency. FYI the other dependecy is angular flex-layout which has an issue targeting es6 currently: https://github.com/angular/flex-layout/issues/950

Ni55aN commented 5 years ago

Another solution can be: import the bundle by "main" property of package.json instead of "module". Honestly I dont know if it is possible without interfering with dependency itself.

mrwhy-orig commented 5 years ago

Same problem here, with a fresh vue.js project. I tried to use the rete.js.org site as a guide. But when it comes to the render process, i get the same error with rete 1.0.0. With a rollback to Beta.5 it works like a charm...

davidgraeff commented 5 years ago

Actually I like to ask if not just es6 features but also es6 modules could be used. Redux for example (see https://www.jsdelivr.com/package/npm/redux) exposes commonjs and also ES builds.

d-led commented 5 years ago

the rete.js.org repo doesn't work either when upgraded to the latest version

Ni55aN commented 5 years ago

@d-led what exactly not working?

d-led commented 5 years ago

I've downloaded the repo source, then npm i -U rete, then npm run serve:

image

Ni55aN commented 5 years ago

@d-led thanks for the found issue. Now I understand the cause of the problem (this happens not only in Angular)

d-led commented 5 years ago

@Ni55aN superb! Glad to have helped

Ni55aN commented 5 years ago

@d-led you can try again with latest version. I have modified CLI to build ES modules using preset-env

Ni55aN commented 5 years ago

Related problem: https://github.com/retejs/rete-cli/issues/2 (seems to be solved)

d-led commented 5 years ago

the next challenge is testing. With 1.0.2 when tests are run the following can be seen:

    TypeError: _rete.Socket is not a constructor

      2 |
      3 | export default {
    > 4 |     num: new Socket('Number value'),
        |          ^
      5 |     action: new Socket('Action'),
      6 |     data: new Socket('Data'),
      7 |     package: new Socket('Package')

      at Object.<anonymous> (src/rete/sockets.js:4:10)

the file is unmodified. import { Socket } from 'rete'; is still there

Ni55aN commented 5 years ago

just cloned rete.js.org repo, installed dependencies and have build the project without any errors. Please check version of package in /node_modules

d-led commented 5 years ago

yes, it builds without errors. This is a test. Will write up how to reproduce

d-led commented 5 years ago

it could be a set up problem, but the result is the same:

https://github.com/d-led/rete.js.org/commit/0c04a7cd050c6d15aa77a568c2959f2273ea633a

simple test:

import { Socket } from '@/rete/sockets';

describe('Examples', () => {
  it('tmp', () => {
    console.log(Socket.num);
  });
});

output:

    TypeError: _rete.Socket is not a constructor

      2 |
      3 | export default {
    > 4 |     num: new Socket('Number value'),
Ni55aN commented 5 years ago

@d-led @/rete/sockets pointing to src/rete/sockets.js. This module does not have a named export Socket. Did you mean import { Socket } from 'rete';?

d-led commented 5 years ago

in fact, the statement in the test is not necessary to reproduce. This is just the unmodified rete.js.org code. Just importing it in the test is sufficient to reproduce: https://github.com/d-led/rete.js.org/commit/694f2f40b3d5fd10856a49f4ed0c7ebecf54f88b

it's the same import as in add-component.js

Ni55aN commented 5 years ago

I see, I'll check it

Ni55aN commented 5 years ago

Not it should works (v1.0.3). The issue was in the module that was imported from Node.js as a UMD module (main field in package.json) instead of CommonJS

d-led commented 5 years ago

Cool. Glad you have figured it out. At the moment I'd be clueless. Cool library, by the way.