Closed liangshengzhong closed 2 years ago
Hi @liangshengzhong! Thanks for reporting. Let us take a look at this issue once we're done with the higher priority tickets. Could you clarify the following questions:
process.env
not present in browser. Could this be the cause of the error?Thank you
@liangshengzhong This library can be used only with Node.js runtime. typed-rest-client is written based on the http and https modules from the Node.
Browser support can be implemented by third-party utilities that replace the implementation of the necessary modules from Node
It will be helpful if you provide a minimal example that reproduced this issue
Hi @liangshengzhong! Thanks for reporting. Let us take a look at this issue once we're done with the higher priority tickets. Could you clarify the following questions:
- Did you try using this rest client for the first time? If not, has there been this problem before? Yes, this is the first time we are trying to use this package in our projects
- As far as I know
process.env
not present in browser. Could this be the cause of the error? I think so, so can you confirm that this is a nodejs only library, or if it supports both browsers and nodejs? I can not get any information about this in document. But I saw there is a react example in sample- Also, could you please share information about the browser you are using? I am using Chrome version 103.0.5060.114 (Official Build) (arm64) Thank you
@AndreyIvanov42 Thank you for your reply。
This library can be used only with Node.js runtime. typed-rest-client is written based on the http and https modules from the Node. This means that by default typed-rest-client is a NodeJS only library, right?
Browser support can be implemented by third-party utilities that replace the implementation of the necessary modules from Node I would appreciate if you could recommend some third-party libraries that can implement that
@AndreyIvanov42 The code to reproduce the issue https://github.com/liangshengzhong/vue-typed-rest-client.
cd vue-typed-rest-client
npm install
npm run dev
Hi @liangshengzhong @KonstantinTyukalov will prepare samples for client use in the browser
Glad to hear that, thanks
@AndreyIvanov42 The code to reproduce the issue https://github.com/liangshengzhong/vue-typed-rest-client.
cd vue-typed-rest-client npm install npm run dev
Hi @liangshengzhong, could you try this workaround for vite config? - https://github.com/vitejs/vite/issues/1973#issuecomment-787571499
@KonstantinTyukalov The workaround resolves the the process does not define
error, but when I try to send a GET request, a new error occurs. I have updated the code to reproduce this error. https://github.com/liangshengzhong/vue-typed-rest-client
browser-external:path:9 Uncaught Error: Module "path" has been externalized for browser compatibility. Cannot access "path.posix" in client code.
at Object.get (browser-external:path:9:13)
at Object.getUrl (Util.js:25:26)
at RestClient.<anonymous> (RestClient.js:51:28)
at Generator.next (<anonymous>)
at RestClient.js:9:71
at new Promise (<anonymous>)
at __awaiter (RestClient.js:5:12)
at RestClient.get (RestClient.js:50:16)
at main.ts:10:31
This issue has had no activity in 90 days. Please comment if it is not actually stale
Environment
Node version: v16.16.0 Npm version: 8.11.0 OS and version: macOS 12.4 typed-rest-client version: 1.8.9 Vue version: 3.2.33 Vite: 3.0.0
Issue Description
We are trying to use this package to interact with the backend APIs in the Vuejs3 front-end project. But always get
httpClient.js:111 uncaught reference error: the process does not define
in browser. I didn't find a way to fix it.Expected behaviour
Actual behaviour
Deosn't work in browser
Steps to reproduce
Logs