schemix
schemix copied to clipboard
RangeError: Invalid array length
Node version: 18.17.0
Schemix version: 1.14.0
Getting this error on a fresh install
node_modules/schemix/dist/modules/PrismaModel.js:204
var paddings = Array(mostTokens).fill(0);
^
RangeError: Invalid array length
at PrismaModel.parseFields (node_modules/schemix/dist/modules/PrismaModel.js:204:24)
at Immediate.<anonymous> (node_modules/schemix/dist/modules/PrismaModel.js:163:27)
at process.processImmediate (node:internal/timers:476:21)
This is also happening to me occasionally. Rerunning the script a few times gets the error to go away somehow
@zygopleural I've written a small script to take care of it until it gets looked into:
#!/bin/bash
# {PROJECT}/prisma/prisma.build
EXECUTOR=bun
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ok() { # Print a green [OK]
local string="$1"
echo -e "\033[1;32m[OK]\033[0m $string"
}
info() { # Print a cyan [INFO]
local string="$1"
echo -e "\033[1;36m[INFO]\033[0m $string"
}
prepend() {
local string="$1"
local file="$2"
printf '%s\n%s' "$string" "$(cat $file)" >$file
}
info "Building prisma schema..."
# Sometimes the script fails inexplicably, so we try until it works
while ! $EXECUTOR $DIR/builder.ts 2> /dev/null; do
sleep 0.1
done
prepend "// DO NOT MODIFY THIS FILE MANUALLY
// This file was autogenerated by schemix in \`./${DIR##*/}/builder.ts\`.
// Use the TS scripts in \`./${DIR##*/}/models/\` to modify the schema
// run \`$EXECUTOR db:generate\` to rebuild the schema
" "${DIR}/schema.prisma"
ok "Prisma schema built successfully"
my predb:generate
does chmod +x ./prisma/prisma.build && ./prisma/prisma.build
~~db:generate
just runs prisma generate
with some private utils, change according to your needs~~
which calls:
// {PROJECT}/prisma/builder.ts
import { createSchema } from 'schemix';
createSchema({
basePath: __dirname,
datasource: {
provider: 'postgresql',
url: { env: 'DATABASE_URL' }
},
generator: {
provider: 'prisma-client-js'
}
}).export(__dirname, 'schema');
until it goes through
Very interesting, could be a race condition. Once I have the time, I'll take a look!
+1 Happens about 10-20% of the time for me