Hi, trying to deploy to Heroku. I successfully ran...
# orm-help
c
Hi, trying to deploy to Heroku. I successfully ran migrations using
heroku run npx prisma migrate deploy
however when I try to seed the database using
heroku run npx prisma db seed
it borks with the following error:
Copy code
Running seed command `ts-node prisma/seed/index.ts` ...

An error occured while running the seed command:
Error: Command failed with ENOENT: ts-node prisma/seed/index.ts
spawn ts-node ENOENT
r
Is the path of the seed correct?
c
Locally yes:
Copy code
Chriss-MBP:api chris$ npx prisma db seed
Environment variables loaded from .env
Running seed command `ts-node prisma/seed/index.ts` ...
Seeding employee model...
Seeding eventPosition model...
Seeding language model...
Maybe the relative path is tripping up Heroku?
r
That’s possible yes.
c
Any suggestions?
Maybe it's not finding the
ts-node
command?
r
Does running
npx ts-node prisma/seed/index.ts
work instead of running
prisma db seed
?
c
Looks like that does install and run
ts-node
however for seeding users my seed file imports a helper function to hash passwords with bcrypt, and it appears TS can't find the dev dependencies for the types:
Copy code
Running npx ts-node prisma/seed/index.ts on ⬢ afscme-local-328-api-staging... up, run.3850 (Hobby)
npm WARN exec The following package was not found and will be installed: ts-node
/app/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:744
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/utils/helpers.ts:3:20 - error TS7016: Could not find a declaration file for module 'bcrypt'. '/app/node_modules/bcrypt/bcrypt.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/bcrypt` if it exists or add a new declaration (.d.ts) file containing `declare module 'bcrypt';`

3 import bcrypt from 'bcrypt'
                     ~~~~~~~~
src/utils/helpers.ts:4:30 - error TS7016: Could not find a declaration file for module 'jsonwebtoken'. '/app/node_modules/jsonwebtoken/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/jsonwebtoken` if it exists or add a new declaration (.d.ts) file containing `declare module 'jsonwebtoken';`

4 import { sign, verify } from 'jsonwebtoken'
                               ~~~~~~~~~~~~~~

    at createTSError (/app/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:744:12)
    at reportTSError (/app/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:748:19)
    at getOutput (/app/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:935:36)
    at Object.compile (/app/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1237:30)
    at Module.m._compile (/app/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1364:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/app/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1368:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  diagnosticText: "\x1B[96msrc/utils/helpers.ts\x1B[0m:\x1B[93m3\x1B[0m:\x1B[93m20\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7016: \x1B[0mCould not find a declaration file for module 'bcrypt'. '/app/node_modules/bcrypt/bcrypt.js' implicitly has an 'any' type.\n" +
    "  Try `npm i --save-dev @types/bcrypt` if it exists or add a new declaration (.d.ts) file containing `declare module 'bcrypt';`\n" +
    '\n' +
    "\x1B[7m3\x1B[0m import bcrypt from 'bcrypt'\n" +
    '\x1B[7m \x1B[0m \x1B[91m                   ~~~~~~~~\x1B[0m\n' +
    "\x1B[96msrc/utils/helpers.ts\x1B[0m:\x1B[93m4\x1B[0m:\x1B[93m30\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7016: \x1B[0mCould not find a declaration file for module 'jsonwebtoken'. '/app/node_modules/jsonwebtoken/index.js' implicitly has an 'any' type.\n" +
    "  Try `npm i --save-dev @types/jsonwebtoken` if it exists or add a new declaration (.d.ts) file containing `declare module 'jsonwebtoken';`\n" +
    '\n' +
    "\x1B[7m4\x1B[0m import { sign, verify } from 'jsonwebtoken'\n" +
    '\x1B[7m \x1B[0m \x1B[91m                             ~~~~~~~~~~~~~~\x1B[0m\n',
  diagnosticCodes: [ 7016, 7016 ]
}
The error mentions adding a declaration file
.d.ts
but I haven't done that before....
not sure if it would help.
r
Do you have the types installed? If not, then try installing them as mentioned in the error. If you do have them installed, then
ts-node
is probably not catching them.
c
The types are only installed as dev dependencies. Would I put that declaration file in the same folder as the file that uses the modules in question i.e. for
src/utils/helpers.ts
I'd add a
src/utils/helpers.d.ts
file?
r
If the types are installed, then the declaration isn’t needed. I think it cannot find the types here in
node_modules
. What’s your
tsconfig.json
look like?
c
Copy code
{
  "compilerOptions": {
    "sourceMap": true,
    "outDir": "dist",
    "strict": true,
    "lib": [
      "esnext"
    ],
    "esModuleInterop": true
  }
}
I'm a beginner at TS so I'm completely open to make any recommended changes.
@Chris V any ideas?
c
Looks like
devDependencies
aren't installed - I checked the contents of
node_modules
on the dyno and they're not there. Seems consistent with what Heroku docs say as well: We’ve updated the default behavior to install all dependencies listed in 
package.json
 during build, and to strip out the developer dependencies before the app is deployed.
I'll trying preventing the pruning of
devDependencies
Setting
YARN_PRODUCTION=false
and
NPM_CONFIG_PRODUCTION=false
did the trick. It prevents the dev dependencies from being pruned, making them available even after the build process
l
But that is not what you want when you go in production. ts-node runs your typescript code, and thus needs the types there, so for such a setup, you actually needs those types in your normal dependencies. If you don't want that, then you should compile your application (using tsc), and then deploy the resulting JS and run it with normal node.