tst-reflect icon indicating copy to clipboard operation
tst-reflect copied to clipboard

[BUG] Uncaught ReferenceError: _ßr is not defined

Open Hookyns opened this issue 3 years ago • 4 comments

This is a known bug

You can find this issue in projects with incremental build and/or HMR. This is fixed in the new major version (not released yet).

Fix

You can hotfix this issue by adding this code somewhere to your project, it has to be executed as soon as possible.

import { getType, Type } from "tst-reflect";
(window as any)["_" + String.fromCharCode(223) + "r"] = { getType, Type };

Example

Lets have create-react-app project. You have to create new file eg. polyfills.ts

import { getType, Type } from "tst-reflect";
(window as any)["_" + String.fromCharCode(223) + "r"] = { getType, Type };

and import this file first in the index.ts.

import "./polyfills";
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

Hookyns avatar Nov 08 '22 19:11 Hookyns

@Hookyns How can I apply this fix to a node server?

paluchi avatar Jan 28 '23 12:01 paluchi

Hi, you can participate in Alpha version (it's fixed there) or you have to declare that variable in "index" file on your own as shown above.

Do you have some specific issue with it?

Hookyns avatar Jan 28 '23 13:01 Hookyns

Hi, you can participate in Alpha version (it's fixed there) or you have to declare that variable in "index" file on your own as shown above.

Do you have some specific issue with it?

It's the same issue you already described. Could you please provide me a link to the alpha subs.? window object does not exist for node servers as it is not running on a web provider

EDIT (Hookyns): idk how, but I edited this instead of reply; reverted

paluchi avatar Jan 28 '23 14:01 paluchi

@paluchi Ahh, okay. You just have to replace window by global or globalThis.

Hookyns avatar Feb 02 '23 16:02 Hookyns