locohost
locohost
Explore posts from servers
CDCloudflare Developers
Created by locohost on 4/20/2024 in #pages-help
I must be missing a bit on CF Pages "functions" folder, it never works for me
pages.dev: https://a37dd34e.lkg-pages-hono.pages.dev deployment id: a37dd34e-3951-4c09-b03a-0ba7b7eca80c account id: 97b74a45f478725ddc37f3f1ddc20277 I have a fairly basic CFP project. It's Typescript, Hono, Drizzle, Tailwindcss with Vite and uses CF KV for auth/users/sessions. It's in really good shape and is fully functional but for one part I just can't seem to "wrangle" 😉 I'd like to move the code that talks to KV and later D1 into "functions". I mean I can certainly create a "repos" folder and put the db code in files there, but I thought it would be fun to try functions in CFP. I added a "functions" folder in project root. I put the example.ts file from the CF docs. I've tried other files too. So far, functions does nothing for me. No function ever works local or deploys and works. My build and deploy scripts in package.json are...
"scripts": {
"dev": "vite",
"build": "vite build",
"deploy:prev": "vite build && wrangler pages deploy --branch preview",
"deploy:prod": "vite build && wrangler pages deploy --branch production"
},
"scripts": {
"dev": "vite",
"build": "vite build",
"deploy:prev": "vite build && wrangler pages deploy --branch preview",
"deploy:prod": "vite build && wrangler pages deploy --branch production"
},
My vite.config.ts looks like...
import build from '@hono/vite-cloudflare-pages'
import devServer from '@hono/vite-dev-server'
import adapter from '@hono/vite-dev-server/cloudflare'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [
build(),
devServer({
adapter,
entry: 'src/index.tsx'
})
]
})
import build from '@hono/vite-cloudflare-pages'
import devServer from '@hono/vite-dev-server'
import adapter from '@hono/vite-dev-server/cloudflare'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [
build(),
devServer({
adapter,
entry: 'src/index.tsx'
})
]
})
I'm sure there is one magic step I'm not seeing in docs so here I am 🙂
7 replies
DTDrizzle Team
Created by locohost on 1/20/2024 in #help
Node app Typescrip drizzle-orm/libsql works fine in terminal, but errors running in Docker container
I've built a Node Express app with Typescript. I'm using Drizzle and TursoDb for the data stuff. Everything works peachy when I'm running the app in terminal. It also builds (tsc) and then the /dist version runs perfectly great. However, when I build a Docker container and the app tries to run, I get an error on the drizzle-orm/libsql line in transpiled JS...
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.db = void 0;
const libsql_1 = require("drizzle-orm/libsql"); // <---- Errors on this line running in Docker container
const client_1 = require("@libsql/client");
const dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config();
let client;
// if (process.env.NODE_ENV == "production") {
console.log("Connected to Turso db");
client = (0, client_1.createClient)({
url: process.env.DATABASE_URL,
authToken: process.env.DATABASE_AUTH_TOKEN,
});
exports.db = (0, libsql_1.drizzle)(client);
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.db = void 0;
const libsql_1 = require("drizzle-orm/libsql"); // <---- Errors on this line running in Docker container
const client_1 = require("@libsql/client");
const dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config();
let client;
// if (process.env.NODE_ENV == "production") {
console.log("Connected to Turso db");
client = (0, client_1.createClient)({
url: process.env.DATABASE_URL,
authToken: process.env.DATABASE_AUTH_TOKEN,
});
exports.db = (0, libsql_1.drizzle)(client);
This is error when Docker image runs...
> NODE_ENV=production && node dist/app.js

/home/node/app/node_modules/drizzle-orm/libsql/index.js:1
export * from "./driver.js";
^^^^^^

SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js
> NODE_ENV=production && node dist/app.js

/home/node/app/node_modules/drizzle-orm/libsql/index.js:1
export * from "./driver.js";
^^^^^^

SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js
Has anyone else experienced this? I'm certain its something dumb on my part. Ofc. Can anyone offer some advice to get this working in the Docker container? Thank you for any help!
3 replies