notiz-dev / nestjs-prisma-starter

Starter template for NestJS 😻 includes GraphQL with Prisma Client, Passport-JWT authentication, Swagger Api and Docker
MIT License
2.37k stars 336 forks source link

fix: add dotenv in devDependencies #452

Closed 100lvlmaster closed 3 years ago

100lvlmaster commented 3 years ago

Running seed after setting up project leads to this error,


Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Running seed from prisma/seed.ts ...
Result:
prisma/seed.ts:2:25 - error TS2307: Cannot find module 'dotenv' or its corresponding type declarations.

2 import \* as dotenv from 'dotenv';
~~~~~~~~

Error: Command failed with exit code 1: ts-node --eval "
// @ts-ignore
declare const require: any

console.info('Result:')

const **seed = require('./prisma/seed.ts')
const **keys = Object.keys(\_\_seed)

async function runSeed() {
// Execute "seed" named export or default export
if (**keys && **keys.length) {
if (**keys.indexOf('seed') !== -1) {
return **seed.seed()
} else if (**keys.indexOf('default') !== -1) {
return **seed.default()
}
}
}

runSeed()
.then(function (result) {
if (result) {
console.log(result)
}
})
.catch(function (e) {
console.error('Error from seed:')
throw e
})

Adding dotenv as a devDependency fixes this issue

marcjulian commented 3 years ago

Thanks @100lvlmaster!