Environment
- Operating System: Linux
- Node Version: v18.20.3
- Nuxt Version: 3.13.2
- CLI Version: 3.14.0
- Nitro Version: 2.9.7
- Package Manager: npm@10.2.3
Reproduction
https://stackblitz.com/edit/nuxt-starter-ra1h6e
Describe the bug
I want to have an utility file to collect some functions that I can use in server endpoints.
Moreover, I wanted to move some functionality from the root utils directory to a module. I followed the official documentation of module creation with example of addTemplate with virtual files. But when I moved the file from the utils directory to the same one in a created module and tried to use the utils file in server handlers, I got the error:
[nitro 15:07:04] ERROR RollupError: [plugin impound] Vue app aliases are not allowed in server runtime. [importing #build/utils/custom from server/api/builtin-utils.get.ts]
The main reason that the #build alias is not allowed in the server handlers and there's no way to import the dynamic built file even if the file content is absolutely the same. It doesn't make modules developments flexible enough honestly.
Do you have any advice to solve my issue?
Additional context
Steps to reproduce
Open the app.vue file. There are 2 requests to endpoints via useFetch. I just wanted to check if there's any difference between built-in server handlers and dynamically created ones in a module.
The custom.ts file is created in the root utils directory. And the file import ~/utils/custom is used in the builtin-utils.get.ts server handler.
import { customFunction as customFunctionBuiltinUtils } from '~/utils/custom';
Than I duplicated the custom.ts file to a new created module. That injected via the general index.ts of the module:
addTemplate({
filename: 'utils/custom',
src: resolve('runtime/utils/custom.ts'),
});
Now we can jump back to the builtin-utils.get.ts server handler file and replace import from
import { customFunction as customFunctionBuiltinUtils } from '~/utils/custom';
to
import { customFunction as customFunctionModuleUtils } from '#build/utils/custom';
When the import replaced, get the error in the terminal. Try to re-run npm run dev in some cases:
[nitro 15:07:04] ERROR RollupError: [plugin impound] Vue app aliases are not allowed in server runtime. [importing #build/utils/custom from server/api/builtin-utils.get.ts]
Logs
[nitro 15:07:04] ERROR RollupError: [plugin impound] Vue app aliases are not allowed in server runtime. [importing #build/utils/custom from server/api/builtin-utils.get.ts]
Environment
Reproduction
https://stackblitz.com/edit/nuxt-starter-ra1h6e
Describe the bug
I want to have an utility file to collect some functions that I can use in server endpoints.
Moreover, I wanted to move some functionality from the root
utilsdirectory to a module. I followed the official documentation of module creation with example ofaddTemplatewith virtual files. But when I moved the file from theutilsdirectory to the same one in a created module and tried to use the utils file in server handlers, I got the error:The main reason that the
#buildalias is not allowed in the server handlers and there's no way to import the dynamic built file even if the file content is absolutely the same. It doesn't make modules developments flexible enough honestly.Do you have any advice to solve my issue?
Additional context
Steps to reproduce
Open the
app.vuefile. There are 2 requests to endpoints viauseFetch. I just wanted to check if there's any difference between built-in server handlers and dynamically created ones in a module.The
custom.tsfile is created in the rootutilsdirectory. And the file import~/utils/customis used in thebuiltin-utils.get.tsserver handler.Than I duplicated the
custom.tsfile to a new created module. That injected via the generalindex.tsof the module:Now we can jump back to the
builtin-utils.get.tsserver handler file and replace import fromto
When the import replaced, get the error in the terminal. Try to re-run
npm run devin some cases:Logs
[nitro 15:07:04] ERROR RollupError: [plugin impound] Vue app aliases are not allowed in server runtime. [importing #build/utils/custom from server/api/builtin-utils.get.ts]