0

I have a large project that works fine. Today I realized that I needed to make a change in one method in one class. So I changed one method in Task.destroy() by adding just one line:

public destroy(clientId: string, userData: UserData, taskData: TaskData): Promise<boolean> {
    const tasks = Task.getTasks();
  new --> const lists = List.getLists();

    assert(Model.isDataOnly(taskData));
    // remove this task from all the lists....
  }

Before this change I my server runs as expected. After the breaking change, when I run my server I see:

NODE_ENV: ====================[ development: laptop.dynazu.com ]====================
DOMAIN:https://laptop.dynazu.com
Debugger listening on ws://127.0.0.1:9229/cb0c2453-7991-4e7e-8cc1-c81afa519198
For help, see: https://nodejs.org/en/docs/inspector
/home/joel/workspace/Tracker/server/api/user/user.controller.js:75
var users = _user2.User.getUsers();
                        ^

TypeError: Cannot read property 'getUsers' of undefined
    at Object.<anonymous> (user.controller.ts:34:20)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Module._compile (/home/joel/workspace/Tracker/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Object.newLoader [as .js] (/home/joel/workspace/Tracker/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (index.ts:3:1)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Module._compile (/home/joel/workspace/Tracker/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Object.newLoader [as .js] (/home/joel/workspace/Tracker/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)

At first I thought perhaps there was an issue with ng or a build tool. However when I did a comparison to the generated code (js, etc.) there were no changes except the tiny expected ones.

And looking at the error and stack trace, it seems like this may be a load problem??? Has anyone seen anything like this?

user.controller.ts:34 is:

const users = User.getUsers();

and User.getUsers is very simple:

  public static getUsers(): monk.ICollection<UserData> {
    log('getUsers()...', db);
    return db.get('users');
  }

which clearly is never reached. Hence it seems to be a load problem? perhaps node-babel??

Is there a way to test this without node-babel?


In a sense I answered how to use babel instead of node-babel.
I did this by duplicating the relevant part of my code that was already converted to E6 code with typescript. I then did

 node_modules/.bin/bower src -d output

And then did

node output/app.js 

hoping that I would find success. Instead I saw:

    NODE_ENV: ====================[ development: laptop.dynazu.com ]====================
    DOMAIN:https://laptop.dynazu.com
    /home/joel/workspace/Tracker/server/output/api/user/user.controller.js:75
    var users = _user2.User.getUsers();
                            ^

    TypeError: Cannot read property 'getUsers' of undefined
        at Object.<anonymous> (/home/joel/workspace/Tracker/server/output/api/user/user.controller.js:75:25)
        at Module._compile (internal/modules/cjs/loader.js:759:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
        at Module.load (internal/modules/cjs/loader.js:628:32)
        at Function.Module._load (internal/modules/cjs/loader.js:555:12)
        at Module.require (internal/modules/cjs/loader.js:666:19)
        at require (internal/modules/cjs/helpers.js:16:16)
        at Object.<anonymous> (/home/joel/workspace/Tracker/server/output/api/user/index.js:9:42)
        at Module._compile (internal/modules/cjs/loader.js:759:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
        at Module.load (internal/modules/cjs/loader.js:628:32)
        at Function.Module._load (internal/modules/cjs/loader.js:555:12)
        at Module.require (internal/modules/cjs/loader.js:666:19)
        at require (internal/modules/cjs/helpers.js:16:16)
        at Object.<anonymous> (/home/joel/workspace/Tracker/server/output/auth/auth.service.js:18:14)
        at Module._compile (internal/modules/cjs/loader.js:759:30)

exactly as before!.

At least now I have the fully translated js and will be able to determine what is seeming to break in the babel translation! (I hope :-).

THE PROBLEM is worse than expected. Looking at the generated code, there don't seem to be ANY issues. It seems the load itself is breaking, as I am now using babel directly and running 'node app.js'... We will see....

The load itself throws an error and deletes the module, hence I see this error that means nothing about 'TypeError: Cannot read property 'getUsers' of undefined' which is a red herring... I am digging deeper... but a bit clueless at this point.

JoelParke
  • 2,676
  • 2
  • 24
  • 38

1 Answers1

0

I discovered after much head scratching and frustration, that I had to remove any indirection in the export of classes. For example for list, I had a list/index.ts:

-export * from './list.model';
-export * from './list.listData';

And then would use imports such as:

import { List, ListData } from '../list';

But this type of indirection would in translation using babel, to create modules that would crash on load!! with strange errors.

When I changed the import above to:

import { List } from '.../list/list.model';
import { ListData } from '.../list/listData';

All would compile and run without and problems.

I hope this helps others!!!

JoelParke
  • 2,676
  • 2
  • 24
  • 38