Closed AbdallahR99 closed 6 months ago
when I added
plugins: [
analog({
nitro: {
alias: {
'@core': 'src/app/core',
'@components': 'src/app/components',
'@pages': 'src/app/pages',
'@environments': 'src/environments',
'@server': 'src/server',
},
},
}),
],
I got this error:
[nitro 11:54:22 AM] ERROR Error: Could not load src/server/auth/odic.client (imported by src/server/routes/auth/login.ts): ENOENT: no such file or directory, open 'D:\Work\ddapp\dd\src\server\auth\odic.client'
almost because of the missing .ts
extension in the ts imports
import { createOidcClient } from '@server/auth/odic.client';
You can use a rollup plugin for this
https://www.npmjs.com/package/rollup-plugin-typescript-paths
installing this as a dev dependency, importing the typescriptPaths plugin, and configuring as:
analog({
nitro: {
rollupConfig: {
plugins: [typescriptPaths({ tsConfigPath: 'tsconfig.base.json', preserveExtensions: true })]
}
}
})
@brandonroberts worked but I start find this warning
"file:///D:/Work/ddapp/dd/node_modules/.pnpm/@analogjs+vite-plugin-nitro@1.0.2/node_modules/@analogjs/vite-plugin-nitro/src/lib/runtime/api-middleware.mjs" is imported by "virtual:#internal/nitro/virtual/server-handlers", but could not be resolved – treating it as an external dependency.
@AbdallahR99 try with the latest release. We resolved some issues with Windows specifically
Unforuntately getting the same error
Using version 1.3.0.
In fact just supplying "rollupConfig" causes this, (and removing it works again);
nitro: {
rollupConfig: {
},
Then any call to a .server route fails.
Ran into this also. Got a fix coming soon
@brandonroberts, your fix worked! I've integrated it into my project, and now I'm able to import from @server/...
. Here’s the configuration that’s working for me:
import {defineConfig} from 'vite';
import analog from '@analogjs/platform';
import { resolve } from 'path';
import {typescriptPaths} from "rollup-plugin-typescript-paths";
// https://vitejs.dev/config/
export default defineConfig(({mode}) => ({
build: {
target: ['es2020'],
},
resolve: {
mainFields: ['module'],
alias: {
'@components': resolve(__dirname, 'src/app/components'),
'@layout': resolve(__dirname, 'src/app/layout'),
'@lib': resolve(__dirname, 'src/app/lib'),
'@models': resolve(__dirname, 'src/models'),
'@services': resolve(__dirname, 'src/app/services'),
'@server': resolve(__dirname, 'src/server')
}
},
plugins: [analog({
vite: {
inlineStylesExtension: 'scss',
},
nitro: {
preset: 'node-server',
rollupConfig: {
plugins: [typescriptPaths({ tsConfigPath: 'tsconfig.json', preserveExtensions: true })]
}
},
})],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['src/test-setup.ts'],
include: ['**/*.spec.ts'],
reporters: ['default'],
},
define: {
'import.meta.vitest': mode !== 'production',
},
}));
I also made sure to include the aliases directly in my tsconfig.json
file rather than in tsconfig.base.json
.
Please provide the environment you discovered this bug in.
Which area/package is the issue in?
vite-plugin-nitro
Description
when I create an alias path for the server folder it gives me error:
then I checked the
dist\.nitro\dev\index.mjs
and I found the imports are like this:the alias paths work fine with the browser files but it throws this error when I use with server files,
I configurated the allies paths as following: in the
tsconfig.json
I put:in the
vite.config.ts
I put:Please provide the exception or error you saw
Other information
No response
I would be willing to submit a PR to fix this issue