-
-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WARNING: import.meta is not available
after updating to 6.20.0
#1185
Comments
I think yours is just a symptom of this: #886 I have a feeling you are using Vite and Vite now assumes ESM incorrectly |
I am using Vite, indeed. I'm struggling to understand how Vite impacts the work of the Orval CLI tool. |
Yeah its weird its because Vite assumes all your code and libraries are ESM modules and Orval is not...it is a CJS module right now. I don't quite fully understand the Vite bundler and how it works I have to admit. |
What I meant is that the warning is issued when running |
@velin-deity any help would be appreciated if you want to track this one down. |
I do want to solve the issue but I still need help understanding how the CLI works. More importantly, what actually happens when a |
OK I marked help wanted. I don't use mutators in my projects but maybe @soartec-lab can answer. |
oh I just checked I used an Axios Mutator with import Axios, { AxiosError, RawAxiosRequestConfig } from "axios";
export const AXIOS_INSTANCE = Axios.create({ baseURL: import.meta.env.REACT_APP_API_SERVER! }); |
Ok, I'll take a look this too. |
If you don't mind, could you please tell me the minimal files, such as "mutator.ts" and "orval.config.js", that would allow me to reproduce this? |
@soartec-lab You should be able to reproduce here https://github.com/velin-deity/test-mutator |
import.meta
is not available" after updating to 6.23.0import.meta
is not available" after updating to 6.24.0
Hi, this thread still has the needs_reproducer tag. Is there anything more we can do aside from @velin-deity's previous comment? |
@deity-jeroen |
Hi. Any progress on this? I get warnings about import.meta.env not being available when I generate client code with orval. It is Vite-related indeed. Is there any way to run the command-line tool in ESM mode? ChatGPT suggested to set |
I am not positive but i think its because of this: #886 I think a couple of things Orval uses like the IBM OpenAPI Validator are not being used in a ES6 kind of way etc. |
is there a workaround how to fix env import using vite? |
Not that I know of |
Looks like a blocker for using Vite + Orval. Is there a fix coming soon? |
I use Vite with Orval and it works fine. I just see the warning printed out but the code works fine. |
▲ [WARNING] "import.meta" is not available with the "cjs" output format and will be empty [empty-import-meta]
I have this warning and the generated code has localhost as url not the one in the env variables |
I am not having this issue I have two env files. env.development
env.production
When I package my production build I see the correct value and everything is working correctly. |
I have this in my axios config instance, and the generated hooks are with localhost:3005 but my env variables is
|
I have the same thing... import Axios, { AxiosError, RawAxiosRequestConfig } from 'axios';
export const AXIOS_INSTANCE = Axios.create({ baseURL: import.meta.env.REACT_APP_API_SERVER! });
export const useAxiosMutator = <T>(): ((config: RawAxiosRequestConfig) => Promise<T>) => {
return (config: RawAxiosRequestConfig) => {
const source = Axios.CancelToken.source();
const promise = AXIOS_INSTANCE({
...config,
cancelToken: source.token
}).then(({ data }) => data);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
promise.cancel = () => {
source.cancel('Query was cancelled by React Query!');
};
return promise;
};
};
export default useAxiosMutator;
// In some case with react-query and swr you want to be able to override the return error type so you can also do it here like this
export type ErrorType<Error> = AxiosError<Error>; |
I just tried generating with removing and it gets the variable from env, i guess the issue is the client i'm using tanstack
|
I have a fully working example here: https://github.com/melloware/quarkus-primereact uses latest TanStack Query an Axios. I am using Farm but I just switched to Farm from Vite and it was working with Vite as well. Feel free to run my code and inspect it. |
@melloware I tried you example, when i run the application the api call is not directed to the env variable |
@JovanaBozhinovska i think you are right i think mine has been accidentally working because its always serving |
can we expect a fix? |
@JovanaBozhinovska this is an open source project so anyone who knows how to fix the issue and willing to fix the issue can submit a fix. |
@JovanaBozhinovska Based on @velin-deity hint it happened somewhere between 6.19.0 and 6.24.0 a great start would be narrowing down exactly what version broke it by walking backwards and trying 6.23, 6.22 etc until we know exactly where it broke then we can start narrowing down which fix caused it. |
@JovanaBozhinovska were you planning on gathering the info requested above? |
@melloware It starts happening in version 6.20.0 in my reproduction repo |
Ok so it broke between 6.19 and 6.20? |
yes, i tried 6.19 and there was no warning. |
looking at the 6.20 release notes: v6.19.1...v6.20.0 I think one of the dependency updates must have broken this: #1003 |
Workaround:
This avoids the |
OK I use Farm which is a Vite clone written in Rust: https://www.farmfe.org/ I didn't have to touch package.json
|
import.meta
is not available" after updating to 6.24.0import.meta
is not available" after updating to 6.20.0
import.meta
is not available" after updating to 6.20.0import.meta
is not available" after updating to 6.20.0
import.meta
is not available" after updating to 6.20.0import.meta is not available
after updating to 6.20.0
@melloware Besides the workaround, should we expect an actual fix? Do you need any further input/help? |
Yep I am more than happy to accept a PR if someone wants to figure it out. I am pretty sure it's related the commit referenced above probably related to the IBM OpenApi Validator. |
What are the steps to reproduce this issue?
mutator
that usesimport.meta
environment variables in the browserorval
to generate the clientWhat happens?
Since orval is packaged in CJS, the CLI throws a warning that
import.meta
will be empty even though the function usingimport.meta
is never executed during generation.What were you expecting to happen?
The
mutator
should be executed without any warnings. Why does orval bother with linting client code?Any logs, error output, etc?
…
Any other comments?
Somewhere between versions 6.19 and 6.23 the build-tooling for orval seems to have changed. I can't find this being mentioned in any of the release notes.
What versions are you using?
Package Version: 6.24.0
The text was updated successfully, but these errors were encountered: