Hookyns / tst-reflect

Advanced TypeScript runtime reflection system
MIT License
340 stars 11 forks source link

[BUG] Watch mode #79

Open lsarrazi opened 2 years ago

lsarrazi commented 2 years ago

Describe the bug Running tst-reflect in watch mode cause an infinite loop and other weirds errors at runtime

(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
(node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency
...

the first compilation in watch mode do actually work, but all the next ones (when we save our files) throw this error at runtime:

_ßr.Type.store.set(2839, { k: 0, isg: false, n: "AnotherOne", fn: "my-webpack-project/src/schemas/schemas.ts:AnotherOne#2839", props: [], indxs: [], args: [] }); 
^

ReferenceError: _ßr is not defined
    at Object.<anonymous> (C:\Users\leo\Documents\enhanced-rest\dist\index.js:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47

To Reproduce Steps to reproduce the behavior:

  1. ttsc --watch

Runtime

If your're wondering, I just made a getType call on a trivial type to get those errors

Hookyns commented 2 years ago

Hi @lsarrazi,

the issue with _ßr is not defined is a known issue, fixed in new upcoming major version. You can hotfix it by adding this to some main TS file:

import { Type, getType } from "tst-reflect";
(window as any)._ßr = { Type, getType };

But I have to check that (node:2824) Warning: Accessing non-existent property 'tracing' of module exports inside circular dependency, that's new for me.