adonisjs / inertia

Official Inertia.js adapter for AdonisJS
MIT License
74 stars 9 forks source link

Can't run adonis in production using Inertia with React and SSR #9

Closed tom-brulin closed 6 months ago

tom-brulin commented 6 months ago

Package version

1.0.0-18

Describe the bug

Hi,

I am experiencing an issue while trying to deploy a fresh AdonisJS app using inertia starter kit with React and SSR.

To run a production build I use the following commands since the npm run start command doesn't work

❯ npm run build
❯ cd build                                                          
❯ npm ci --omit="dev"                                               
❯ node bin/server.js  

The error

[13:15:30.416] INFO (10512): started HTTP server on localhost:3333
[13:15:30.499] ERROR (10512): Failed to load url inertia/app/ssr.tsx (resolved id: inertia/app/ssr.tsx). Does the file exist?
    request_id: "n3bwaaf65r5jm7npvw13gzp2"
    x-request-id: "n3bwaaf65r5jm7npvw13gzp2"
    err: {
      "type": "Error",
      "message": "Failed to load url inertia/app/ssr.tsx (resolved id: inertia/app/ssr.tsx). Does the file exist?",
      "stack":
          Error: Failed to load url inertia/app/ssr.tsx (resolved id: inertia/app/ssr.tsx). Does the file exist?

After some research, I just copied the inertia directory to the build directory, and it work but I am wondering if it should work like that ?

Reproduction repo

https://github.com/tom-brulin/adonis-inertia-react-ssr-deploy-test

Julien-R44 commented 6 months ago

did you set NODE_ENV to production in your build ?

tom-brulin commented 6 months ago

Oh yeah that's working like a charm right now.

I just copied the default env, and I forgot to change the NODE_ENV

Thanks to you.

decoderid commented 5 months ago

doesn't work on windows

LOG

{
    "level": 60,
    "time": 1712363053805,
    "pid": 12032,
    "hostname": "DESKTOP-BOSTFRL",
    "request_id": "yx7s6nxjwkbl5zc7ln43awd0",
    "err": {
        "type": "Error",
        "message": "Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'",
        "stack": "Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'\n    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11)\n    at defaultLoad (node:internal/modules/esm/load:130:3)\n    at ModuleLoader.load (node:internal/modules/esm/loader:403:13)\n    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:56)\n    at new ModuleJob (node:internal/modules/esm/module_job:67:26)\n    at #createModuleJob (node:internal/modules/esm/loader:297:17)\n    at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:254:34)\n    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:235:17)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:322:23)",
        "code": "ERR_UNSUPPORTED_ESM_URL_SCHEME",
        "status": 500
    },
    "msg": "Exception raised by error handler"
}

ENV

TZ=UTC
PORT=3333
HOST=localhost
LOG_LEVEL=info
APP_KEY=YhOBs4czdPkg4PqeL4eVoYn93qJWQS8V
NODE_ENV=production
SESSION_DRIVER=cookie
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_DATABASE=testing

PROBLEM

import { defineConfig } from '@adonisjs/inertia';
export default defineConfig({
    rootView: 'inertia_layout',
    sharedData: {
        errors: (ctx) => ctx.session?.flashMessages.get('errors'),
    },
    ssr: {
        enabled: true,
        entrypoint: 'inertia/app/ssr.tsx'
    }
});
//# sourceMappingURL=inertia.js.map
edikurniawan-dev commented 4 months ago

doesn't work on windows

LOG

{
    "level": 60,
    "time": 1712363053805,
    "pid": 12032,
    "hostname": "DESKTOP-BOSTFRL",
    "request_id": "yx7s6nxjwkbl5zc7ln43awd0",
    "err": {
        "type": "Error",
        "message": "Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'",
        "stack": "Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'\n    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11)\n    at defaultLoad (node:internal/modules/esm/load:130:3)\n    at ModuleLoader.load (node:internal/modules/esm/loader:403:13)\n    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:56)\n    at new ModuleJob (node:internal/modules/esm/module_job:67:26)\n    at #createModuleJob (node:internal/modules/esm/loader:297:17)\n    at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:254:34)\n    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:235:17)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:322:23)",
        "code": "ERR_UNSUPPORTED_ESM_URL_SCHEME",
        "status": 500
    },
    "msg": "Exception raised by error handler"
}

ENV

TZ=UTC
PORT=3333
HOST=localhost
LOG_LEVEL=info
APP_KEY=YhOBs4czdPkg4PqeL4eVoYn93qJWQS8V
NODE_ENV=production
SESSION_DRIVER=cookie
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_DATABASE=testing

PROBLEM

import { defineConfig } from '@adonisjs/inertia';
export default defineConfig({
    rootView: 'inertia_layout',
    sharedData: {
        errors: (ctx) => ctx.session?.flashMessages.get('errors'),
    },
    ssr: {
        enabled: true,
        entrypoint: 'inertia/app/ssr.tsx'
    }
});
//# sourceMappingURL=inertia.js.map

me too in windows 11