Trouble Implementing Absolute Paths in Farm Project Using Aliases #1743
-
Question:Trouble Implementing Absolute Paths in Farm Project Using Aliases I've been working on a React project, and to simplify my imports, I decided to use absolute paths instead of relative paths like Error Message:[ Farm ] Using config file at C:\Users\devwo\OneDrive\Desktop\Projects\farm-fe-tutorial\farm.config.ts
[ building ] ⠂ transform (136) node_modules/.pnpm/[email protected]/node_modules/core-js/internals/to-length.js.farm-runtime
[ Farm ] Error: Failed to build: Error: Can not resolve `@AppTypes/commonTypes` from src/main.tsx.
Original error: None.
Potential Causes:
1.The file that `@AppTypes/commonTypes` points to does not exist.
2.Install it first if `@AppTypes/commonTypes` is an dependency from node_modules, if you are using pnpm refer to [https://pnpm.io/faq#pnpm-does-not-work-with-your-project-here] for solutions.
3. If `@AppTypes/commonTypes` is a alias, make sure your alias config is correct.
ELIFECYCLE Command failed with exit code 1. File Structure:
Relevant Code:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AnyType = any;
import { AnyType } from "@AppTypes/commonTypes";
// Other imports and code...
import { defineConfig } from "@farmfe/core";
export default defineConfig({
plugins: ["@farmfe/plugin-react"],
compilation: {
resolve: {
alias: {
"@AppTypes/*": "./src/@types/*",
},
},
},
});
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": "./",
"paths": {
"@AppTypes/*": ["./src/@types/*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
} Steps Taken:
Issue:Despite the configurations being correct and the file existing at the specified path, the build process fails to resolve the alias Request for Assistance:I'm seeking help to identify any potential misconfigurations or overlooked aspects that might be causing this issue. Any insights or suggestions would be greatly appreciated. For more details, please review my GitHub repository. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Farm does not support configuring wildcard alias. And the alias value should be absolute path. Following farm.config.ts would work: import path from 'path'
import { defineConfig } from "@farmfe/core";
export default defineConfig({
plugins: ["@farmfe/plugin-react"],
compilation: {
resolve: {
alias: {
"@AppTypes/": path.join(__dirname, 'src', '@types'),
},
},
},
}); |
Beta Was this translation helpful? Give feedback.
Farm does not support configuring wildcard alias. And the alias value should be absolute path. Following farm.config.ts would work: