schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs, SSR and SSG.
https://jasprpad.schultek.de
MIT License
1.13k stars 68 forks source link

jaspr build does not work inside nix #282

Open RossComputerGuy opened 2 weeks ago

RossComputerGuy commented 2 weeks ago

Description

nomics-web-client> Running phase: configurePhase
nomics-web-client> no configure script, doing nothing
nomics-web-client> Executing dartConfigHook
nomics-web-client> Setting up SDK
nomics-web-client> Installing dependencies
nomics-web-client> Finished dartConfigHook
nomics-web-client> Running phase: buildPhase
nomics-web-client> PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)
nomics-web-client> [CLI] Building jaspr for static rendering mode.
nomics-web-client> ⠙ [CLI] Building web assets...... (0ms)Bad state: Unable to start build daemon.

Steps To Reproduce

  1. Use jaspr_cli to set up a basic site
  2. Add jaspr_cli to dev dependencies
  3. Use yq . pubspec.lock > pubspec.lock.json
  4. Add the default.nix below and nix-build.
{ pkgs ? import <nixpkgs> }:
pkgs.buildDartApplication {
  pname = "web";
  version = "0.0.0";

  src = ./.;

  buildPhase = ''
    runHook preBuild

    packageRunCustom jaspr_cli jaspr bin -- build

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    cp -r build/jaspr $out

    runHook postInstall
  '';

  sdkSourceBuilders = {
    # https://github.com/dart-lang/pub/blob/e1fbda73d1ac597474b82882ee0bf6ecea5df108/lib/src/sdk/dart.dart#L80
    "dart" = name: pkgs.runCommand "dart-sdk-${name}" { passthru.packageRoot = "."; } ''
      for path in '${pkgs.dart}/pkg/${name}'; do
        if [ -d "$path" ]; then
          ln -s "$path" "$out"
          break
        fi
      done

      if [ ! -e "$out" ]; then
        echo 1>&2 'The Dart SDK does not contain the requested package: ${name}!'
        exit 1
      fi
    '';
  };

  pubspecLock = pkgs.lib.importJSON ./pubspec.lock.json;
}

Expected Behavior

Jaspr should build

Additional Context

Requires an overlay for nix to support Dart 3.5.1

RossComputerGuy commented 2 weeks ago

Issue seems to be with dart pub get being called from a sandbox, jaspr should have a switch to be able to disable dart pub get.

schultek commented 2 weeks ago

I have never used nix, nor do I even know what it is. So sadly its out of my knowledge to help you with this.

schultek commented 2 weeks ago

This error:

PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)

looks like its coming from https://pub.dev/packages/cli_completion

RossComputerGuy commented 2 weeks ago

The CLI completion error doesn't prevent building, I added verbose logging and got a socket error. For whatever reason, jaspr is fetching from pub.dev inside a networkless sandbox.

schultek commented 2 weeks ago

The cli is checking for updates everytime a command is run. But this is try/catched so any exception shouldn't crash the cli.

The build command itself is effectively only doing dart compile and build_runner build. It may spin up its own local http server but without any network requests.

Can you post the full error you get from running in verbose mode?

RossComputerGuy commented 2 weeks ago
nomics-web-client> PathNotFoundException: Creation failed, path = '/homeless-shelter/.dart-cli-completion' (OS Error: No such file or directory, errno = 2)
nomics-web-client> [CLI] Building jaspr for static rendering mode.
nomics-web-client> [CLI] Building web assets...
nomics-web-client> [BUILDER] [ERROR] Got socket error trying to find package lints at https://pub.dev.
nomics-web-client> Bad state: Unable to start build daemon
schultek commented 2 weeks ago

Weird this is coming from the builder.

Can you try running 'dart run build_runner build' instead of 'jaspr build'?

RossComputerGuy commented 2 weeks ago
web> Running phase: buildPhase
web> [INFO] Generating build script completed, took 205ms
web> [INFO] Precompiling build script... completed, took 2.8s
web> [INFO] Building new asset graph completed, took 1.7s
web> [INFO] Found 1 declared outputs which already exist on disk. This is likely because the`.dart_tool/build` folder was deleted, or you are submitting generated files to your source repository.
web> Delete these files?
web> 1 - Delete
web> 2 - Cancel build
web> 3 - List conflicts
web>
web>
web> You have hit a bug in build_runner
web> Please file an issue with reproduction steps at https://github.com/dart-lang/build/issues
web>
web>
web> Null check operator used on a null value
web> package:build_runner_core/src/environment/io_environment.dart 67:41           IOEnvironment.prompt
web> package:build_runner_core/src/environment/overridable_environment.dart 63:16  OverrideableEnvironment.prompt
web> package:build_runner_core/src/generate/build_definition.dart 546:41           _Loader._initialBuildCleanup
web> package:build_runner_core/src/generate/build_definition.dart 283:17           _Loader.prepareWorkspace.<fn>
web> package:build_runner_core/src/logging/logging.dart 25:30                      logTimedAsync
web> package:build_runner_core/src/generate/build_definition.dart 280:13           _Loader.prepareWorkspace
web> package:build_runner_core/src/generate/build_impl.dart 114:27                 BuildImpl.create
web> package:build_runner_core/src/generate/build_runner.dart 34:26                BuildRunner.create
web> package:build_runner/src/generate/build.dart 109:17                           build
web> package:build_runner/src/entrypoint/build.dart 35:18                          BuildCommand._run
web> package:args/command_runner.dart 212:13                                       CommandRunner.runCommand
web> package:build_runner/src/entrypoint/run.dart 26:18                            run
web> .dart_tool/build/entrypoint/build.dart 210:16                                 main
schultek commented 2 weeks ago

Run with --delete-conflicting-outputs

RossComputerGuy commented 2 weeks ago

Yeah, that worked.