Comments (5)
I'm also affected by this. When loading the seed and factories an assumption is made that the path is relative and never absolute.
typeorm-seeding/src/utils/file.util.ts
Lines 6 to 10 in 9b614d4
process.cwd()
on line 8
If we dig into TypeORM's implementation in how they resolve files (like entities, migrations, etc) you'll notice they do a simple check to see if the path is absolute (ie, the path has a leading slash), and if it is then they don't prepend to it.
TypeORM seeding should most likely also follow this convention. Another potential issue I see is that this library prepends relative paths with the current working directory (cwd) rather than from the package root directory (or the directory containing the ormconfig file). This will most likely burn people using yarn workspaces or lerna or those running typeorm-seeding from a different directory (ie, npm run --prefix different/path ...
)
from typeorm-seeding.
Hello @Pegase745 use resolve
like this
import { resolve } from "path";
export const ORMConfig = {
// ...
seeds: [
resolve(__dirname, './seeds/**/*.seed.ts'),
],
factories: [
resolve(__dirname, './factories/**/*.factory.ts'),
],
// ...
};
from typeorm-seeding.
hi @bpatram thanks for the tip. :-)
I now use the ConnectionOptionReader of TypeORM.
Check out the new version 1.4.0
from typeorm-seeding.
@diegoazh your solution will not work since the paths defined must be relative, not absolute ones like you get when calling resolve
.
@Pegase745 Here is the hacky workaround I am using until this issue is resolved. Using your example, you can do something like:
// ormconfig.js
module.exports = {
seeds: [path.relative(process.cwd(), `${__dirname}/seeds/*.js`)],
// ...
};
Obviously, this example is a bit contrived... but in some cases this is needed (like when the root to your config is different than your cwd (eg, monorepos).
Since the seeds and factories paths are always going to be prefixed with the cwd we can just work backwards from there in order to still resolve using your absolute path. We can use Node's builtin path.relative
to give us a path to our absolute path relative to the cwd.
from typeorm-seeding.
I'm having the same issue with this config:
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
const typeOrmConfig: TypeOrmModuleOptions = {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'postgres',
database: 'payments',
entities: [__dirname + '/../**/*.entity.{js,ts}'],
synchronize: true,
};
// Need to export like this to make typeorm-seeding work, otherwise driver:undefined
// https://github.com/typeorm/typeorm/issues/4068
module.exports = typeOrmConfig
After yarn run seed:run
(which is ts-node ./node_modules/typeorm-seeding/dist/cli.js seed --configName typeorm.config.ts
) it stuck on a database connection step and fail with this error:
✖ Database connection failed! Check your typeORM config file.
../nest-master/integration/typeorm/src/photo/photo.entity.ts:1:56 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.
1 import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
~~~~~~~~~
error Command failed with exit code 1.
If i remove __dirname
everything works.
from typeorm-seeding.
Related Issues (20)
- update major faker version please HOT 1
- Faker npm package not supported HOT 1
- Faker got abandoned and NPM audit complains about it HOT 1
- TypeError: Cannot read properties of undefined(reading 'number') HOT 3
- Support [email protected] HOT 2
- how to truncate tables? HOT 1
- There is a typo for the shebang in the dist/cli.js HOT 1
- Example for how to seed ManyToMany relation HOT 1
- [Request] Support for typeorm 0.3 and nestjs/typeorm v8.1.0 HOT 1
- Database connection failed! Check your typeORM config file. MissingDriverError: Wrong driver: "undefined" given. HOT 4
- this.subQuery is not a function HOT 1
- [Request] Support for typeorm 0.3 and nestjs/typeorm v8.1.0 HOT 20
- Replace `faker` with `@faker-js/faker` HOT 2
- Hello. I just have a question HOT 1
- TypeError: Cannot read properties of undefined (reading 'name')
- prevent seed:config to log any output
- How to seed data with monorepo workspace in nestjs HOT 4
- unable to resolve dependency tree HOT 8
- Publish 1.6.2 HOT 2
- Doesn't finish command
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm-seeding.