Giter Club home page Giter Club logo

Comments (12)

sancelot avatar sancelot commented on June 2, 2024 2

Yes,I can. let me get a little time to dit it next week.

from remult.

noam-honig avatar noam-honig commented on June 2, 2024 1

Gotit - I'll make a few adjustments and merge it

from remult.

noam-honig avatar noam-honig commented on June 2, 2024

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:

  1. Change the vite.config.ts to vite.config.tsm
  2. Change the tsconfig.node.json to include it.

2. Change the entire node js project to esm

  1. In the package.json file, add "type":"module" (the reverse of what we instruct in the react tutorial.
  2. In tsconfig.server.ts remove "module": "commonjs"
  3. 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.

sancelot avatar sancelot commented on June 2, 2024

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.

noam-honig avatar noam-honig commented on June 2, 2024

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.

sancelot avatar sancelot commented on June 2, 2024

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.

noam-honig avatar noam-honig commented on June 2, 2024

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.

noam-honig avatar noam-honig commented on June 2, 2024

Did you deploy only the dist folder - or the entire folder?

from remult.

sancelot avatar sancelot commented on June 2, 2024

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.

noam-honig avatar noam-honig commented on June 2, 2024

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.

sancelot avatar sancelot commented on June 2, 2024

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.

noam-honig avatar noam-honig commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.