blitz icon indicating copy to clipboard operation
blitz copied to clipboard

`blitz db seed` doesn't work with javascript projects

Open sirrobert opened this issue 2 years ago • 3 comments

What is the problem?

I get two main errors when I try blitz db seed. I found other reports marked as closed/done (e.g. https://github.com/blitz-js/legacy-framework/issues/701), but the error persists (for me).

The issue only happens with JavaScript installs, not TypeScript.

Paste all your error logs here:

This is the complete terminal output.

 tmp 
:/ $ blitz --version
Linux 5.11 | linux-x64 | Node: v16.13.0

blitz: 0.44.4 (global)

  Package manager: npm 
  System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (4) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 1.03 GB / 7.73 GB
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: Not Found
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: Not Found
    blitz: Not Found
    prisma: Not Found
    react: Not Found
    react-dom: Not Found
    typescript: Not Found


 tmp 
:/ $ node --version
v16.13.0
 tmp 
:/ $ nvm --version
0.34.0
 tmp 
:/ $ blitz new testapp
✔ You have the latest Blitz version
✔ Pick a new project's language · JavaScript
✔ Pick your new app template · full
✔ Install dependencies? (Y/n) · true
✔ Pick a form library (you can switch to something else later if you want) · React Final Form

Hang tight while we set up your new Blitz app!

CREATE    .env
CREATE    .env.local
CREATE    .env.test.local
CREATE    .eslintrc.js
CREATE    README.md
CREATE    app/auth/components/LoginForm.js
CREATE    app/auth/components/SignupForm.js
CREATE    app/auth/mutations/changePassword.js
CREATE    app/auth/mutations/forgotPassword.js
CREATE    app/auth/mutations/forgotPassword.test.js
CREATE    app/auth/mutations/login.js
CREATE    app/auth/mutations/logout.js
CREATE    app/auth/mutations/resetPassword.js
CREATE    app/auth/mutations/resetPassword.test.js
CREATE    app/auth/mutations/signup.js
CREATE    app/auth/pages/forgot-password.js
CREATE    app/auth/pages/login.js
CREATE    app/auth/pages/reset-password.js
CREATE    app/auth/pages/signup.js
CREATE    app/auth/validations.js
CREATE    app/core/components/Form.js
CREATE    app/core/components/LabeledTextField.js
CREATE    app/core/hooks/useCurrentUser.js
CREATE    app/core/layouts/Layout.js
CREATE    app/pages/404.js
CREATE    app/pages/_app.js
CREATE    app/pages/_document.js
CREATE    app/pages/index.js
CREATE    app/pages/index.test.js
CREATE    app/users/queries/getCurrentUser.js
CREATE    babel.config.js
CREATE    blitz.config.js
CREATE    db/index.js
CREATE    db/schema.prisma
CREATE    db/seeds.js
CREATE    jest.config.js
CREATE    jsconfig.json
CREATE    mailers/forgotPasswordMailer.js
CREATE    package.json
CREATE    public/favicon.ico
CREATE    public/logo.png
CREATE    test/setup.js
CREATE    test/utils.js

WARN Failed to fetch latest version of 'zod', falling back to '3.x'. 
WARN Failed to fetch latest version of '@prisma/client', falling back to '3.x'. 
WARN Failed to fetch latest version of 'prisma', falling back to '3.x'. 
✔ Retrieving the freshest of dependencies
✔ Installing those dependencies (this will take a few minutes)
✔ Initializing SQLite database
✔ Formatting your code
✔ Committing your app

Your new Blitz app is ready! Next steps:

   1. cd testapp
   2. blitz dev

 tmp 
:/ $ cd testapp
 tmp  testapp 
:/ $ blitz db seed
Loaded env from /home/sirrobert/tmp/tmp/testapp/.env.local
Loaded env from /home/sirrobert/tmp/tmp/testapp/.env
ERROR Could not seed database: 

 Error  Cannot find module 'typescript'
Require stack:
- /home/sirrobert/tmp/tmp/testapp/node_modules/ts-node/dist/index.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@blitzjs/cli/lib/src/utils/setup-ts-node.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@blitzjs/cli/lib/src/commands/db.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/config/lib/plugin.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/config/lib/config.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/config/lib/index.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/command/lib/command.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/command/lib/index.js
- /home/sirrobert/tmp/tmp/testapp/node_modules/@blitzjs/cli/lib/src/index.js
- /home/sirrobert/.nvm/versions/node/v16.13.0/lib/node_modules/blitz/cli/dist/blitz-cli.cjs.dev.js
- /home/sirrobert/.nvm/versions/node/v16.13.0/lib/node_modules/blitz/cli/dist/blitz-cli.cjs.js
details:
{
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/sirrobert/tmp/tmp/testapp/node_modules/ts-node/dist/index.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@blitzjs/cli/lib/src/utils/setup-ts-node.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@blitzjs/cli/lib/src/commands/db.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/config/lib/plugin.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/config/lib/config.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/config/lib/index.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/command/lib/command.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@oclif/command/lib/index.js',
    '/home/sirrobert/tmp/tmp/testapp/node_modules/@blitzjs/cli/lib/src/index.js',
    '/home/sirrobert/.nvm/versions/node/v16.13.0/lib/node_modules/blitz/cli/dist/blitz-cli.cjs.dev.js',
    '/home/sirrobert/.nvm/versions/node/v16.13.0/lib/node_modules/blitz/cli/dist/blitz-cli.cjs.js'
  ]
}
error stack:
• loader:933 Module._resolveFilename
    node:internal/modules/cjs/loader:933:15

• v8-compile-cache.js:164 resolve
    node_modules/v8-compile-cache/v8-compile-cache.js:164:23

• index.ts:439 loadCompiler
    node_modules/ts-node/src/index.ts:439:30

• index.ts:445 create
    node_modules/ts-node/src/index.ts:445:26

• index.ts:410 register
    node_modules/ts-node/src/index.ts:410:19

• setup-ts-node.js:8 setupTsnode
    node_modules/@blitzjs/cli/lib/src/utils/setup-ts-node.js:8:28

• db.js:15 <anonymous>
    node_modules/@blitzjs/cli/lib/src/commands/db.js:15:43

• tslib.js:117 <anonymous>
    node_modules/tslib/tslib.js:117:75

 tmp  testapp 
:/ $ npm install --save-dev typescript

added 1 package, and audited 1528 packages in 6s

160 packages are looking for funding
  run `npm fund` for details

12 vulnerabilities (8 moderate, 4 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

:/ $ blitz db seed
Loaded env from /home/sirrobert/tmp/tmp/testapp/.env.local
Loaded env from /home/sirrobert/tmp/tmp/testapp/.env
Couldn't find tsconfig.json. tsconfig-paths will be skipped
Seeding database
◢ Loading seeds
ERROR Couldn't import default from db/seeds 
ERROR Could not seed database: 

 SyntaxError  Unexpected token 'export'

Paste all relevant code snippets here:

What are detailed steps to reproduce this?

From Ubuntu 21.04

Steps

  1. npm install --global blitz@latest
  2. blitz new testapp
  3. Selected:
    1. Dialect: JavaScript
    2. Template: Full
    3. Install Deps: Yes
    4. Forms Lib: React Final Form
  4. cd testapp
  5. blitz db seed

If I do exactly the same steps but use TypeScript instead, it works as expected.

Run blitz -v and paste the output here:

:/ $ blitz --version
Loaded env from /home/sirrobert/tmp/tmp/jsapp/.env.local
Loaded env from /home/sirrobert/tmp/tmp/jsapp/.env
Linux 5.11 | linux-x64 | Node: v16.13.0

blitz: 0.44.4 (global)
blitz: 0.44.4 (local)

  Package manager: npm 
  System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (4) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 1.00 GB / 7.73 GB
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: Not Found
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 3.x => 3.7.0 
    blitz: 0.44.4 => 0.44.4 
    prisma: 3.x => 3.7.0 
    react: 18.0.0-beta-149b420f6-20211119 => 18.0.0-beta-149b420f6-20211119 
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    typescript: Not Found

Please include below any other applicable logs and screenshots that show your problem:

Here's the diff between the TS and JS versions of package.json

:/ $ diff -u --color jsapp/package.json tsapp/package.json 
--- jsapp/package.json	2021-12-28 10:59:47.392362690 -0500
+++ tsapp/package.json	2021-12-28 10:53:38.637088953 -0500
@@ -1,12 +1,12 @@
 {
-  "name": "jsapp",
+  "name": "testapp",
   "version": "1.0.0",
   "scripts": {
     "dev": "blitz dev",
     "build": "blitz build",
     "start": "blitz start",
     "studio": "blitz prisma studio",
-    "lint": "eslint --ignore-path .gitignore --ext .js .",
+    "lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx .",
     "test": "jest",
     "test:watch": "jest --watch",
     "prepare": "husky install"
@@ -19,7 +19,7 @@
     "printWidth": 100
   },
   "lint-staged": {
-    "*.{js}": [
+    "*.{js,ts,tsx}": [
       "eslint --fix"
     ]
   },
@@ -33,14 +33,17 @@
     "zod": "3.x"
   },
   "devDependencies": {
-    "eslint": "7.32.0",
+    "@types/preview-email": "2.0.1",
+    "@types/react": "17.0.38",
+    "eslint": "7.x",
     "husky": "7.0.4",
     "lint-staged": "11.3.0-beta.2",
     "prettier": "2.5.1",
     "prettier-plugin-prisma": "3.7.0",
     "pretty-quick": "3.1.3",
     "preview-email": "3.0.5",
-    "prisma": "3.x"
+    "prisma": "3.x",
+    "typescript": "~4.5"
   },
   "private": true
 }

sirrobert avatar Dec 28 '21 16:12 sirrobert

My temporary work-around is to create a parallel typescript app in a different directory and copy .env, .env.local, ./db/seed.js, ./db/schema.prisma into it (with a script).

sirrobert avatar Dec 28 '21 22:12 sirrobert

Thanks for reporting it, and sorry about the behaviour. Looks like db seed does not work with JavsScript projects.

beerose avatar Dec 30 '21 19:12 beerose

Hello, i noticed that blitz install doesn't work either in javascript mode

andrearizzello avatar Jun 11 '22 22:06 andrearizzello