Closed ttingeyqfym closed 8 months ago
Hi @ttingeyqfym, for using relative imports, mongoose-tsgen looks for the paths field to be set in your tsconfig.json file. Are you able to use this option? If not, I'd be happy to look at supporting rootDir
if you can provide me a simple repo that reproduces your setup.
@ttingeyqfym Have you had a chance to try the paths
field mentioned above?
@francescov1
Not sure if this is the issue related to my question, but in my models files, i do imports like this at the top of my file:
import { Site } from '@/types'
I have this tsconfig:
{
"compilerOptions": {
"target": "ES2022",
// "lib": [],
// "experimentalDecorators": true,
// "emitDecoratorMetadata": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"baseUrl": "./src", // Set the base directory for relative paths
"paths": {
"@/*": ["*"] // Map @/* to */ (any file in the base directory)
},
// "moduleResolution": "node10",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
and I keep getting a syntax error here:
$ npx mtgen -d ./src/lib/models/ --debug
Debug mode enabled
Generating mongoose typescript definitions... !
SyntaxError: Cannot use import statement outside a module
zsh: exit 1 npx mtgen -d ./src/lib/models/ --debug
@samislam I think this is due to your package.json missing the line "type": "module"
.
If you're still running into issues, itd be great if you can provide a simple repo that reproduces the issue and Id be happy to investigate.
@samislam I think this is due to your package.json missing the line
"type": "module"
.If you're still running into issues, itd be great if you can provide a simple repo that reproduces the issue and Id be happy to investigate.
I have type module.
I see. Could you create a simple repo to reproduce the issue and I'll investigate? Often these issues are related to the combo of packages being used so hard to debug without seeing the entire setup.
@samislam Found the issue, its related to ESNext. Fix is now live in v9.2.13!
I'm trying to configure mtgen so that my models can use relative imports. IE import { obj } from 'src/enums/obj' and I can't seem to figure out how to configure mtgen to allow it. I have a tsconfig.json set with the rootDir and is working for all other imports, just breaks when mtgen runs.