Encountering an error while attempting to import files using aliases in the configuration file (nuxt.config.ts): Cannot find module '~/....
For reference, please check out this example: codesnadbox.io
Showcasing a Short Example
nuxt.config.ts
import { book } from "~/vars";
export default defineNuxtConfig({
runtimeConfig: {
bookApiEndpoint: book.apiEndpoint || "",
},
});
Detailed Example:
If using an absolute path, the file can be properly imported:
import { book } from "./vars";
However, importing through an alias within the file may lead to another error (refer to pic.1):
./vars.ts
export * from "~/entities";
./entities/index.ts
export * from "./book";
./entities/book.ts
export const book = {
apiEndpoint: '/api/book'
}
For further illustration, you can visit: codesnadbox.io
Inquiry:
How can aliases be effectively utilized within a config file?
Your assistance is greatly appreciated!
For more insights, feel free to explore: codesnadbox.io