-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
resolve.alias doesn't work on vite builds #13960
Comments
Vite now has no defineConfig? |
I have exactly the same problem. @moecasts, have you found any solutions? |
I had modified the resolve function that replace the alias before the function execute. async transform(value, path) {
if (!resolve) {
resolve = (source, importer, options) => {
const mergedOptions: typeof options = Object.assign(
{
skipSelf: true,
},
options,
);
const currentAlias = find(alias, { find: source });
if (currentAlias?.replacement) {
const realSource = source.replace(source, currentAlias.replacement);
return this.resolve(realSource, importer, mergedOptions);
}
return this.resolve(source, importer, mergedOptions);
};
} |
I am also running into this issue; I actually used configResolved(resolvedConfig) {
if (resolvedConfig.resolve && Array.isArray(resolvedConfig.resolve?.alias)) {
// These needs to be at the top of the array to take precedence
resolvedConfig.resolve.alias.unshift(
{
find: 'react-native/Libraries/Image/AssetRegistry',
replacement: 'react-native-web/dist/modules/AssetRegistry',
},
{
find: 'react-native-web/Libraries/Image/AssetRegistry',
replacement: 'react-native-web/dist/modules/AssetRegistry',
},
);
console.log(JSON.stringify(resolvedConfig));
}
}, I get errors on build about those paths not existing but I do not on serve. |
I am using this configuration to find and replace TypeScript aliases, and it is working in both development and build environments. I hope it proves helpful to you. import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [react()],
resolve: {
alias: [
{
find: '@common/components',
replacement: resolve(__dirname, './src/common/components'),
},
{
find: '@common/icons',
replacement: resolve(__dirname, './src/common/icons'),
},
{
find: '@common/layout',
replacement: resolve(__dirname, './src/common/layout'),
},
{
find: '@common/apis',
replacement: resolve(__dirname, './src/common/apis'),
}]
}) |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
Hi @hossamt93, import react from "@vitejs/plugin-react";
import path from "path";
import { defineConfig } from "vite";
// import { fileURLToPath, URL } from 'node:url'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src/"),
},
},
}); I get this error: I just created a new React project with TypeScript using vite. |
Just run
|
@migsdeving |
I confirmed that the reproduction in OP was fixed in 5.0.0-beta.3. I guess rollup/plugins#1402 fixed it. |
Describe the bug
When I run
vite dev
,resolve.alias
has works.But, when I run
vite build
, it won't works.this is my code:
Reproduction
https://github.com/moecasts/vite-resolve-alias-build-demo
Steps to reproduce
pnpm i && pnpm --filter 'package-*' build && pnpm build
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: