Comments (12)
Yes,I can. let me get a little time to dit it next week.
from remult.
Gotit - I'll make a few adjustments and merge it
from remult.
I'm assuming you also get the "The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details." error when you build.
This is because you're using the common js version of vite (as we show in the tutorial for maximum backward compatibility) and that package is esm.
You have several options:
1. use esm for vite only:
- Change the
vite.config.ts
tovite.config.tsm
- Change the
tsconfig.node.json
to include it.
2. Change the entire node js project to esm
- In the
package.json
file, add"type":"module"
(the reverse of what we instruct in the react tutorial. - In
tsconfig.server.ts
remove"module": "commonjs"
- In all the file references done from node js, add the
.js
extension
import {api} from './api.js'
Let me know that it worked for you
from remult.
I used the second proposal , and to modify a bit the server
//index.ts
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(express.static(path.join(__dirname, "../")));
from remult.
Great - would you be willing to do a PR and update the tutorial to use ESM to begin with? (remove the text about removing "type":"module" and make the adjustments you did?
from remult.
Hi, I made a pull request. When working again on it trying to deploy, I faced problems where node was unable to load the .js file as esm module.
=> I had to deploy a package.json file in the dist build containing {"type":"module"} and everything worked as expected
from remult.
Hi @sancelot - can you share the code you played with - or the final result?
I didn't run into this problem in my conference talks where I use esm - here's my starting repo:
https://github.com/noam-honig/todo-app
from remult.
Did you deploy only the dist folder - or the entire folder?
from remult.
Did you deploy only the dist folder - or the entire folder?
I deployed the dist folder. I can not share code . I made a small mistake in the PR , I will correct
from remult.
Ok - in the tutorial we deploy the entire folder.
If you only deploy the dist folder, you anyhow need another package json to instruct node to install pg for postgres etc...
from remult.
At the moment I stick to json db.
I can share the beginning content of dist/server/index.js , obviously nothing obfuscated :
/ src/server/index.ts
import express from "express";
import { api } from "./api.js";
import { extract } from "tar-stream"; // Import Parse type from tar-stream
import { open } from "node:fs/promises";
import cors from "cors";
import * as crypto from "crypto";
import * as fs from "fs";
import helmet from "helmet";
import compression from "compression";
import path from "path";
import { fileURLToPath } from "url";
import { remult } from "remult";
import { Features } from "../shared/features.js";
import os from "os";
let host = "";
const app = express();
app.use(api);
app.use(cors());
app.use(helmet({
contentSecurityPolicy: false,
crossOriginOpenerPolicy: false,
originAgentCluster: false,
}));
app.use(compression());
const version_fao = 2;
let memorized_cksum = "";
function getFileChecksum(filePath) {
return new Promise((resolve, reject) => {
const hash = crypto.createHash("md5");
const stream = fs.createReadStream(filePath);
stream.on("data", (data) => hash.update(data));
stream.on("end", () => resolve(hash.digest("hex")));
stream.on("error", reject);
});
}
from remult.
I've merged your PR and did a few more adjustments to the tutorials - check it out at:
https://remult.dev/tutorials/react/
from remult.
Related Issues (20)
- 403 forbidden even when user is allowed HOT 9
- Better way to type a string property as a union of string subtypes? HOT 5
- Hono and Elysia Backend Remult Support HOT 5
- 403 status livequery custom monorepo todo app HOT 18
- Issue with Repository 'find' Method: Syntax Error Results in Unintended Data Query HOT 3
- feature: ability to add Entity properties that related to Open API HOT 3
- Doc: Offline Support HOT 3
- Doc: DB Migrations HOT 4
- Whether to support bun:sqlite HOT 7
- howto access the repo from backend HOT 5
- [Feature Request] allow customized query function HOT 7
- server backend build fails HOT 4
- toOne creates link fields in both tables HOT 1
- How can i custom the logic of compile the entity and filter to raw sql? HOT 16
- How to support multiple data provider HOT 1
- import Credentials moved from @auth/core to @auth/sveltekit HOT 1
- Do not trigger all `@Relations.toOne` before a `saving` hook HOT 2
- On a `500` error, don't retry 50 times HOT 3
- [improvement] @Relations.toMany & findOptions from Frontend HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remult.