Nitro aliases cannot be imported in the Vue part of your app. [importing #config from service/index.ts]
See original GitHub issueEnvironment
- Operating System:
Windows_NT
- Node Version:
v16.11.0
- Nuxt Version:
3.0.0-27465767.70f067a
- Package Manager:
yarn@1.22.4
- Builder:
vite
- User Config:
publicRuntimeConfig
- Runtime Modules:
-
- Build Modules:
-
Reproduction
nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3'
// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
publicRuntimeConfig: {
ENV_TEXT: process.env.ENV_TEXT
}
})
./service/index.ts
import config from '#config'
export const useService = () => {
// ...
console.log(config.ENV_TEXT)
// ...
}
./pages/index.vue
<script setup lang="ts">
import { onMounted } from 'vue'
import { useService } from '@/service'
onMounted(() => {
console.log(useService)
})
</script>
<template>
<div>
</div>
</template>
Describe the bug
I tried to use import config from '#config'
in service according to the documentation but it doesn’t work
error log
ERROR 下午8:47:18 [vite] Internal server error: Failed to resolve import "#config" from "service\index.ts". Does the file exist?
20:47:18
Plugin: vite:import-analysis
File: D:/Alex/nuxt3-app/service/index.ts
1 | import config from "#config";
| ^
2 | export const useService = () => {
3 | console.log(config.ENV_TEXT);
document https://v3.nuxtjs.org/docs/usage/runtime-config#api-routes
Additional context
No response
Logs
[plugin:vite:import-analysis] Failed to resolve import "#config" from "service\index.ts". Does the file exist?
D:/Alex/nuxt3-app/service/index.ts:1:0
1 | import config from "#config";
| ^
2 | export const useService = () => {
3 | console.log(config.ENV_TEXT);
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Nitro aliases cannot be imported in the Vue part of your app ...
I want to build nuxt3 app to spa with vuetify3. I set ssr: false, target:"static" in nuxt.config.ts and ran the command "yarn build"....
Read more >`Vue3 - Vite` project alias src to @ not working - Stack Overflow
In the vite.config.js file write the below code blocks import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import path ...
Read more >How to fix "resolve.alias" problem in Vite.js - Raul Melo
My package is just a collection of small functions written in TS. ... import path from "path"; import { defineConfig } from "vite"; ......
Read more >Nuxt Configuration Reference
Build your next Vue.js application with confidence using Nuxt. ... assets/images', import.meta.url)), 'style': fileURLToPath(new URL('.
Read more >The alias Property - Nuxt
These aliases can be used within your JavaScript and CSS. nuxt.config.js import { resolve } from 'path' export default { alias: { 'images': ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ohhh! Thank you very much for your patient answer 🎉
Can you please try
server/api/index.ts
? (note that api is not a top-level directory)