Closed SazhinDima closed 4 years ago
@SazhinDima are you trying to run the ts-proto
output in Node on the backend or in a browser on the frontend?
@SazhinDima I'm guessing that you're trying to run in the browser, where globalThis
needs to be used instead of global
. Can you try version 1.21.2? If you're still having issues, let me know more details about what environment you're trying to run in and what your tsconfig
looks like.
@stephenh i'm runing in the Node.js (react project)
tscinfig:
{ "compilerOptions": { "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "jsx": "react", "target": "es2018", "baseUrl": ".", "experimentalDecorators": true, "skipLibCheck": true, "typeRoots": [ "./node_modules/@types" ] }, "include": [ "src/*/", "globalCss.d.ts" ], "exclude": [ "node_modules", "dist" ] }
If i put in top: declare var global: any;
evethig works correct. But i don't know is it ok.
You probably need to do npm install @types/node
because global
comes from node. This is not a ts-proto issue but just a TypeScript/node issue, so please use stackoverflow/etc. to resolve from here on out.
If someone still have this issue, try using globalThis
instead
Hi @JeViCo , thanks for the note; per globalThis
, yes, at this point we have a pretty elaborate function to get the right global object:
const tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw "Unable to locate global object";
})();
And then we do throw new tsProtoGlobalThis.Errror(...)
I generated typescript file and try to import it. But i have error "TS2304: Cannot find name 'global'" on line throw new global.Error("Value is larger than Number.MAX_SAFE_INTEGER");
Help me please.