Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to run a compiled nest app #28563

Open
xyber-nova opened this issue Mar 20, 2025 · 8 comments
Open

Failed to run a compiled nest app #28563

xyber-nova opened this issue Mar 20, 2025 · 8 comments
Labels
bug Something isn't working correctly compile related to the `deno compile` feature

Comments

@xyber-nova
Copy link

Version: Deno 2.2.4

With default nest.js template. Only changed main.js as

import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const swaggerConfig = new DocumentBuilder()
    .setTitle('Backend API')
    .setDescription('The Backend')
    .setVersion('0.0.1-alpha.1')
    .build();

  const documentFactory = () => SwaggerModule.createDocument(app, swaggerConfig)

  SwaggerModule.setup('docs', app, documentFactory);

  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();

and tsconfig.json

{
  "compilerOptions": {
    "module": "ES2022",
    "moduleResolution": "bundler",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2023",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "forceConsistentCasingInFileNames": true,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "noFallthroughCasesInSwitch": false
  }
}

How to Replication

  1. run command deno run build
  2. run command deno compile --unstable-sloppy-imports -A --include dist/ --output dist.bin dist/main.js
  3. execute dist.bin
  4. try to open the swagger ui

Note

I can get the expected behavior when use deno dist/main.ts, but unexpected when use binary.

@dsherret
Copy link
Member

Can you add the error you get or what goes wrong?

@dsherret dsherret added the needs info needs further information to be properly triaged label Mar 20, 2025
@xyber-nova
Copy link
Author

here are error messages.

error: Uncaught (in promise) TypeError: Cannot read properties of null (reading 'toUTCString')
    var modified = stat.mtime.toUTCString()
                              ^
    at SendStream.setHeader (file:///tmp/deno-compile-dist.bin/node_modules/.deno/[email protected]/node_modules/send/index.js:759:31)
    at SendStream.send (file:///tmp/deno-compile-dist.bin/node_modules/.deno/[email protected]/node_modules/send/index.js:509:8)
    at onstat (file:///tmp/deno-compile-dist.bin/node_modules/.deno/[email protected]/node_modules/send/index.js:616:10)
    at Deno.stat.then.denoErrorToNodeError.syscall (ext:deno_node/_fs/_fs_stat.ts:151:32)
    at eventLoopTick (ext:core/01_core.js:177:7)

the error may because fs.stat cannot be used in self contained executable?

// file:///tmp/deno-compile-dist.bin/node_modules/.deno/[email protected]/node_modules/send/index.js:616:10
  fs.stat(path, function onstat (err, stat) {
    var pathEndsWithSep = path[path.length - 1] === sep
    if (err && err.code === 'ENOENT' && !extname(path) && !pathEndsWithSep) {
      // not found, check extensions
      return next(err)
    }
    if (err) return self.onStatError(err)
    if (stat.isDirectory()) return self.redirect(path)
    if (pathEndsWithSep) return self.error(404)
    self.emit('file', path, stat)
    self.send(path, stat)
  })

@dsherret dsherret added bug Something isn't working correctly compile related to the `deno compile` feature and removed needs info needs further information to be properly triaged labels Mar 20, 2025
@xyber-nova
Copy link
Author

most the information not contained to the executable file.

// debug information from the executable file
stat Stats {
  dev: 0,
  ino: 0,
  mode: 0,
  nlink: 0,
  uid: 0,
  gid: 0,
  rdev: 0,
  size: 154985,
  blksize: 0,
  blocks: 0,
  mtime: null,
  atime: null,
  birthtime: null,
  mtimeMs: null,
  atimeMs: null,
  birthtimeMs: null,
  isFile: [Function: isFile],
  isDirectory: [Function: isDirectory],
  isSymbolicLink: [Function: isSymbolicLink],
  isBlockDevice: [Function: isBlockDevice],
  isFIFO: [Function: isFIFO],
  isCharacterDevice: [Function: isCharacterDevice],
  isSocket: [Function: isSocket],
  ctime: null,
  ctimeMs: null
}

// normally run
stat Stats {
  dev: 2080,
  ino: 815699,
  mode: 33188,
  nlink: 2,
  uid: 1000,
  gid: 1000,
  rdev: 0,
  size: 154985,
  blksize: 4096,
  blocks: 304,
  mtime: 1985-10-26T08:15:00.000Z,
  atime: 2025-03-20T16:02:40.530Z,
  birthtime: 2025-03-20T16:02:40.330Z,
  mtimeMs: 499162500000,
  atimeMs: 1742486560530,
  birthtimeMs: 1742486560330,
  isFile: [Function: isFile],
  isDirectory: [Function: isDirectory],
  isSymbolicLink: [Function: isSymbolicLink],
  isBlockDevice: [Function: isBlockDevice],
  isFIFO: [Function: isFIFO],
  isCharacterDevice: [Function: isCharacterDevice],
  isSocket: [Function: isSocket],
  ctime: 2025-03-20T16:02:40.000Z,
  ctimeMs: 1742486560000
}

@dsherret
Copy link
Member

Thank you. It helps to see what the error is because that often gives an idea on what the fix is.

In this case, probably these values should be hardcoded with the date that the compiled executable was made:

deno/cli/rt/file_system.rs

Lines 1257 to 1260 in 60b502d

atime: None,
birthtime: None,
mtime: None,
ctime: None,

@xyber-nova
Copy link
Author

yes. And according the definition of fs.Stats, it should be a number. null value is a unexpected behavior.

I think I can create a PR to fix it.

@dsherret
Copy link
Member

I think I can create a PR to fix it.

That would be helpful. Thanks!

I think as a quick fix we could just use std::sync::OnceLock and store the first accessed time, but ideally we could just store the time in

pub struct Metadata {
then surface that there.

@xyber-nova
Copy link
Author

I think I can create a PR to fix it.

That would be helpful. Thanks!

I think as a quick fix we could just use std::sync::OnceLock and store the first accessed time, but ideally we could just store the time in

pub struct Metadata {
then surface that there.

yeah. I think we can storage a metadata called build_time in the binary file, and surface them in FsStats of VfsFiles.

Also I think deno can add a interface in stdlib to get compile-time data like env! macro in rust. It maybe useful when identity informations of backend application in production I thought.

@xyber-nova
Copy link
Author

For convenience, I will use Box::leak to create a globally OnceLock<&'static Metadata> static variable and use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly compile related to the `deno compile` feature
Projects
None yet
Development

No branches or pull requests

2 participants