Blitz: `blitz db seed` error: Cannot find module

Created on 2 Oct 2020  ยท  28Comments  ยท  Source: blitz-js/blitz

What is the problem?

When running blitz seed blitz db seed the module db/seeds.ts cannot be found.

Steps to Reproduce

  1. Create new blitz app on latest canary.
  2. Run blitz seed blitz db seed
  3. See error:
Error: Cannot find module '/Users/simon/Code/myapp/db/seeds'

Versions

0.23.2-canary.3
0.24.1
(Node 14)

Edit: I've updated the issue to reflect the renamed command blitz seed -> blitz db seed, see more information in comment below.

kinbug priorithigh statudone

Most helpful comment

@peaonunes I've tested with latest blitz (0.24.1) and a fresh project, still not working. But there is a new error message, seems like the thrown error is handled now:

โ—ข Loading seeds
โœ• Couldn't import default from db/seeds.ts or db/seeds/index.ts file


blitz --version --verbose (Node 14)

macOS Catalina | darwin-x64 | Node: v14.7.0

blitz: 0.24.1 (global)
blitz: 0.24.1 (local)

  Package manager: npm 
  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 8.19 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.7.0 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/node
    Yarn: Not Found
    npm: 6.14.7 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/cli: 2.8.0 => 2.8.0 
    @prisma/client: 2.8.0 => 2.8.0 
    blitz: 0.24.1 => 0.24.1 
    react: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    react-dom: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    typescript: 4.0.3 => 4.0.3 

I've also tested with Node 12 now, same result:


blitz --version --verbose (Node 12)

macOS Catalina | darwin-x64 | Node: v12.18.4

blitz: 0.24.1 (global)
blitz: 0.24.1 (local)

  Package manager: npm 
  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 6.99 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.4 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/node
    Yarn: Not Found
    npm: 6.14.6 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/cli: 2.8.0 => 2.8.0 
    @prisma/client: 2.8.0 => 2.8.0 
    blitz: 0.24.1 => 0.24.1 
    react: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    react-dom: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    typescript: 4.0.3 => 4.0.3 

All 28 comments

I believe the issue was fixed at https://github.com/blitz-js/blitz/pull/1239
I could not reproduce it in the latest 0.24.1.

@peaonunes i don't think so. Only it was renamed from blitz seed to blitz db seed

@peaonunes i don't think so. Only it was renamed from blitz seed to blitz db seed

Interesting! I've cloned the latest, bootstrapped an app and ran the blitz db seed and worked fine. The differences from the my setup from the reported in the issue are that I'm at the latest local on canary, and the node (mine is 12, not 14, do we support node 14?).
Screen Shot 2020-10-07 at 13 42 43

@peaonunes I've tested with latest blitz (0.24.1) and a fresh project, still not working. But there is a new error message, seems like the thrown error is handled now:

โ—ข Loading seeds
โœ• Couldn't import default from db/seeds.ts or db/seeds/index.ts file


blitz --version --verbose (Node 14)

macOS Catalina | darwin-x64 | Node: v14.7.0

blitz: 0.24.1 (global)
blitz: 0.24.1 (local)

  Package manager: npm 
  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 8.19 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.7.0 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/node
    Yarn: Not Found
    npm: 6.14.7 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/cli: 2.8.0 => 2.8.0 
    @prisma/client: 2.8.0 => 2.8.0 
    blitz: 0.24.1 => 0.24.1 
    react: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    react-dom: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    typescript: 4.0.3 => 4.0.3 

I've also tested with Node 12 now, same result:


blitz --version --verbose (Node 12)

macOS Catalina | darwin-x64 | Node: v12.18.4

blitz: 0.24.1 (global)
blitz: 0.24.1 (local)

  Package manager: npm 
  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 6.99 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.4 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/node
    Yarn: Not Found
    npm: 6.14.6 - /var/folders/3z/gw5jft154vs93chj00bm1sw40000gn/T/fnm-shell-2589620/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/cli: 2.8.0 => 2.8.0 
    @prisma/client: 2.8.0 => 2.8.0 
    blitz: 0.24.1 => 0.24.1 
    react: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    react-dom: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8 
    typescript: 4.0.3 => 4.0.3 

@peaonunes I've tested with latest blitz (0.24.1) and a fresh project, still not working. But there is a new error message, seems like the thrown error is handled now:

โ—ข Loading seeds
โœ• Couldn't import default from db/seeds.ts or db/seeds/index.ts file

blitz --version --verbose (Node 14)

I've also tested with Node 12 now, same result:
blitz --version --verbose (Node 12)

That's odd, I'm gonna recreate my setup and try again. I was hoping to fix it, but I need to reproduce it first lol

Very strange. I've just tried in a container (VSCode devcontainer), but I still get the same error.

Just to be sure it is not a silly error on my side: This commands below should work to get the empty seeds function to run, right?

npm install -g blitz@latest
blitz new myApp
cd myApp
blitz db migrate
blitz db seed

I can also confirm, this does not work in a fresh node container. This should be reproducable:

// Run docker
docker run -it node /bin/bash

// Inside docker container
// Global install of blitz fails because of some permission issues, 
// so I had to install in a local folder first
cd /root
npm init -y
npm install blitz

npx blitz new app
cd app
npx blitz db migrate
npx blitz db seed

I'm getting the error 'Couldn't import default from db/seeds.ts or db/seeds/index.ts file' when trying to run blitz db seed on a new installation using the latest version of the CLI.

Here's a stack trace:

[Error: Cannot find module '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/db/seeds'
Require stack:
- /Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/blitz/node_modules/@blitzjs/cli/lib/src/commands/db.js
- /Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/config/lib/plugin.js
- /Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/config/lib/config.js
- /Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/config/lib/index.js
- /Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/command/lib/command.js
- /Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/command/lib/index.js
- /Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/blitz/node_modules/@blitzjs/cli/lib/src/index.js
- /Users/aaronfulkerson/.nvm/versions/node/v14.13.0/lib/node_modules/blitz/dist/cli.js] {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/blitz/node_modules/@blitzjs/cli/lib/src/commands/db.js',
    '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/config/lib/plugin.js',
    '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/config/lib/config.js',
    '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/config/lib/index.js',
    '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/command/lib/command.js',
    '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/@oclif/command/lib/index.js',
    '/Volumes/Samsung Portable SSD T3 Media/amweb-blitz/node_modules/blitz/node_modules/@blitzjs/cli/lib/src/index.js',
    '/Users/aaronfulkerson/.nvm/versions/node/v14.13.0/lib/node_modules/blitz/dist/cli.js'
  ]
}

Seems to be choking on this line: seeds = require(seedPath).default;

Doesn't it have something to do with Node not knowing how to read a .ts file?

I also checked. I'll check it out as soon as possible.

It worked after the yarn link in the current canary branch, so the
Perhaps I missed it because of the difference in behavior between yarn link and unlinked

~/c/spkb (feat/add-write-lesson|โ€ฆ) $ blitz db seed                                                            01:42:20
You are using alpha software - if you have any problems, please open an issue here:
      https://github.com/blitz-js/blitz/issues/new/choose

Seeding database
โ—ข Loading seeds
โœ• Couldn't import default from db/seeds.ts or db/seeds/index.ts file
~/c/spkb (feat/add-write-lesson|โ€ฆ) $ yarn link blitz                                                          01:42:26
yarn link v1.22.4
success Using linked package for "blitz".
โœจ  Done in 0.12s.
~/c/spkb (feat/add-write-lesson|โ€ฆ) $ blitz db seed                                                            01:44:34
You are using alpha software - if you have any problems, please open an issue here:
      https://github.com/blitz-js/blitz/issues/new/choose

Seeding database
โœ” Loading seeds

โ—ข Checking for database migrations
Everything up-to-date
โ—ฃ Checking for database migrations
๐Ÿ‹๏ธโ€  migrate up

โ—ข Checking for database migrations

โœ” Generated Prisma Client (version: 2.7.1) to ./node_modules/@prisma/client in 192ms

You can now start using Prisma Client in your code:

``
import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()
``

โ—ฃ Checking for database migrations
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                         โ”‚
โ”‚  Update available 2.7.1 -> 2.8.1                        โ”‚
โ”‚  Run npm i --save-dev @prisma/cli to update             โ”‚
โ”‚                                                         โ”‚
โœ” Checking for database migrations

> Seeding...
โœ” Done seeding

Set up verdaccio and debug

I'm trying to find a way to reproduce this problem.

I was able to register @blitz/cli into the local private npm registry, but publishing the blitz itself is private and I get an error.
Is there any way to fix this?
Or you know other approch?


cli publish: (success. but I don't know hou to access)

  1. verdaccio (start local private npm registry)
  2. cd packages/cli
  3. yarn build
  4. add touch .npmrc -> registry=http://localhost:4873
  5. npm version patch
  6. npm publish --registry=http://localhost:4873

blitz app publish: (failed.)

  1. verdaccio (start local private npm registry)
  2. add touch .npmrc -> registry=http://localhost:4873
  3. edit package.json -> "publish-canary": "yarn run publish-prep && lerna publish --registry http://localhost:4873 --force-publish --preid canary --pre-dist-tag canary",
  4. yarn publish-latest -- --registry=http://localhost:4873
$ lerna publish --registry http://localhost:4873 --force-publish --preid canary
info cli using local version of lerna
lerna notice cli v3.22.1
lerna info current version 0.24.2-canary.0
lerna ERR! EBEHIND Local branch 'canary' is behind remote upstream origin/canary
lerna ERR! EBEHIND Please merge remote changes into 'canary' with 'git pull'

Can you share your seeds file? i had the same problem.. but after a log.error(err) inside the exception handler of the seed method.. i realized that it was due to a syntax error inside a string.
And it worked fine after i fixed that error.

// import db from "./index"

/*
 * This seed function is executed when you run `blitz db seed`.
 *
 * Probably you want to use a library like https://chancejs.com
 * or https://github.com/Marak/Faker.js to easily generate
 * realistic data.
 */
const seed = async () => {
  // for (let i = 0; i < 5; i++) {
  //   await db.project.create({ data: { name: "Project " + i } })
  // }
}

export default seed

This is with latest blitz (0.24.3), fresh generated project.
Edit: Forgot to mention, the issue is still there.

In case this is helpful, wanted to share that I hit this as well on a fresh generated project (0.24.3)

And in the spirit of testing I got a local clone of the main blitz repo, ran through the [contributors guide[(https://blitzjs.com/docs/contributing) (props on that by the way!) and got everything set up with yarn dev and yarn link-cli.

Then I ran yarn link blitz in my generated project, followed by blitz db seed hoping to hack away at whatever was going wrong, and โœจ the error was gone.

So I can reproduce @nitaking's issue that this is really hard to reproduce ๐Ÿ˜…

For what it's worth, I didn't install blitz globally initially, instead using npx blitz db seed. That still fails for me and debugging the built package is really tricky to get into. But now that I've got blitz set up with the dev cli globally, it _does_ work. So maybe this has something to do with the usage of npx (followed by, I set up a seed script in my project's package.json).

It seems this works fine with the local dev version of blitz, but not with a blitz version from npm.

Resolved by @nemesv :)

Can we reopen this issue? The seeding fails if you try importing something from another file.

Can we reopen this issue? The seeding fails if you try importing something from another file.

Perhaps that is a different issue to review import functions support. Or is that failing out of the box after bootstrapping the blitz app?

It should fail after bootstrapping a new app. Try importing the hashPassword function from the auth-utils file.

@aaronfulkerson open a new issue for that

Hello everyone,

blitz db seed still gives me the error

yarn run v1.22.4
$ blitz db seed
You are using alpha software - if you have any problems, please open an issue here:
      https://github.com/blitz-js/blitz/issues/new/choose

Seeding database
โ—ข Loading seeds
โœ• Couldn't import default from db/seeds.ts or db/seeds/index.ts file
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If I run yarn link blitz I get

yarn link v1.22.4
error No registered package found called "blitz".
info Visit https://yarnpkg.com/en/docs/cli/link for documentation about this command.

blitz --version

You are using alpha software - if you have any problems, please open an issue here:
      https://github.com/blitz-js/blitz/issues/new/choose

Linux 5.6 | linux-x64 | Node: v12.16.2

blitz: 0.23.2 (global)
blitz: 0.25.0 (local)

  Package manager: yarn
  System:
    OS: Linux 5.6 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
    Memory: 1.46 GB / 15.57 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.16.2 - ~/.nvm/versions/node/v12.16.2/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.2/bin/npm
    Watchman: 4.9.0 - /usr/bin/watchman
  npmPackages:
    @prisma/cli: 2.11.0 => 2.11.0
    @prisma/client: 2.4.1 => 2.4.1
    blitz: 0.25.0 => 0.25.0
    react: 0.0.0-experimental-33c3af284 => 0.0.0-experimental-33c3af284
    react-dom: 0.0.0-experimental-33c3af284 => 0.0.0-experimental-33c3af284
    typescript: 3.9.7 => 3.9.7

@maotora does it still fail if you run yarn blitz db seed ?

@flybayer Not sure if I tried that option but I made an npm script like, "seed": "blitz db seed" which I used yarn run seed to run.

Did it work?

No, it didn't work.

Same error,

yarn run v1.22.4
$ /home/user/Projects/project/node_modules/.bin/blitz db seed
You are using alpha software - if you have any problems, please open an issue here:
      https://github.com/blitz-js/blitz/issues/new/choose

Seeding database
โ—ข Loading seeds
โœ• Couldn't import default from db/seeds.ts or db/seeds/index.ts file
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@maotora ok, please open a new issue and include as many details and logs as possible

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flybayer picture flybayer  ยท  4Comments

yhoiseth picture yhoiseth  ยท  3Comments

flybayer picture flybayer  ยท  4Comments

SharadKumar picture SharadKumar  ยท  3Comments

svobik7 picture svobik7  ยท  3Comments