0

I have created a docker file to containerise my Dart application. It creates a main application image, install all the necessary packages and copies my project into the container.

I have three packages to build that are next to each other, like so:

-- packages

---- package1

---- package2

---- package3

so I have use melos to facilitate building everything in one go.

However, when I then try to run melos bootstrap it yields me an error which appears to start from melos package itself all the way up to a pubspec loadFile parser:

# melos bs
Unhandled exception:
Null check operator used on a null value
#0      new JsonParser (package:pubspec/src/json_utils.dart:87:48)
#1      parseJson (package:pubspec/src/json_utils.dart:13:5)
#2      new PubSpec.fromJson (package:pubspec/src/pubspec.dart:96:15)
#3      PubSpec.loadFile (package:pubspec/src/pubspec.dart:128:15)
<asynchronous suspension>
#4      PackageMap.resolvePackages.<anonymous closure> (package:melos/src/package.dart:542:25)
<asynchronous suspension>
#5      Future.wait.<anonymous closure> (dart:async/future.dart:522:21)
<asynchronous suspension>
#6      PackageMap.resolvePackages (package:melos/src/package.dart:539:5)
<asynchronous suspension>
#7      MelosWorkspace.fromConfig (package:melos/src/workspace.dart:65:25)
<asynchronous suspension>
#8      _Melos.createWorkspace (package:melos/src/commands/runner.dart:100:13)
<asynchronous suspension>
#9      _BootstrapMixin.bootstrap (package:melos/src/commands/bootstrap.dart:5:23)
<asynchronous suspension>
#10     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#11     MelosCommandRunner.runCommand (package:melos/src/command_runner.dart:80:5)
<asynchronous suspension>
#12     main (file:///root/.pub-cache/hosted/pub.dev/melos-2.9.0/bin/melos.dart:46:5)
<asynchronous suspension>

When I run it in my local version, I don't appear to have this problem and only happens within the docker container. Most of the resources of questions online refer to somewhere in the code which uses a null check operator "!" on a variable that is already null. However, in this case, the file the error references is not my own but from an internal package.

I am new to dart and melos and was wondering if anybody has come across this error and if they have any hints on why this is being raised within a container but not when run locally

Thank you in advance for any help.

my melos.yaml


packages:
  - packages/**

scripts:
  analyze:
    exec: dart analyze .
  get:
    exec: dart pub get

My DockerFile:

### main application image ###
FROM dart:stable

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y cmake build-essential gperf libssl-dev zlib1g-dev \
    && rm -rf /var/lib/apt/lists/*

# Install packages
RUN apt update \
    && apt install -y \
    libc++-dev \
    && rm -rf /var/lib/apt/lists/*


RUN rm -rf /app && mkdir -p /app
COPY . /app

ENV PATH="/root/.pub-cache/bin:${PATH}"

WORKDIR /app

RUN rm -rf packages/td_json_client/build && \
 mkdir packages/td_json_client/build && \
 cd packages/td_json_client/build && \
 cmake -DCMAKE_INSTALL_PREFIX:PATH=/app/packages/td_json_client/lib/src/blobs/darwin/arm64 /app/packages/td_json_client/lib/src/log_callback && \
 cmake --build . --target install


RUN ls /app/packages/td_json_client/build
RUN ls /app/packages/td_json_client/lib/src/blobs/darwin/arm64


RUN cp -r /app/packages/td_json_client/lib/src/blobs/darwin/arm64 /usr/local/lib/

RUN dart pub global activate melos
# I commented out the code below so I could sh into the docker image
# RUN melos bootstrap 
# RUN melos run get
# CMD ["/app/packages/cli/bin/main.dart","login","-h","--api-id=","$API_ID", \
#     "--api-hash=","$API_HASH","--phone-number=","$PHONE", \
#     "--libtdjson-path=","$PATH_TD_JSON_LIB","--libtdjson-loglevel=","$LOG_LEVEL"]

I tried to verify if it came from anywhere within my code by adding the --scope option, e.g. melos bootstrap --scope package/package1 melos bootstrap --scope package/package2 melos bootstrap --scope package/package3

but they all yielded the same error, indicating that I probably have something that is not set up correctly.

I was expecting to see something similar to what I get locally, which is:

Running "dart pub get" in workspace packages...
  ✓ <packagename1>
    └> packages/<packagename1>
  ✓ <packagename2>
    └> packages/<packagename2>
  ✓ <packagename3>
    └> packages/<packagename3>

Linking workspace packages...
  > SUCCESS

Generating IntelliJ IDE files...
  > SUCCESS
  • Could you provide dockerfile? – Alexander Farkas Jan 31 '23 at 17:29
  • Also, try to bash into your built container. Something wrong may catch your eye. – Alexander Farkas Jan 31 '23 at 17:32
  • I have added the DockerFile. Yes I did that and unfortunately could not find anything alarming that is differently set up from my local setup – Guilherme Vieira Jan 31 '23 at 17:39
  • Seems that your pubspec files get corrupted when moved. Make sure they have the same encoding both on local machine and docker – Alexander Farkas Jan 31 '23 at 18:13
  • When checking the encoding of files in local and the files in the docker, they both have `pubspec.yaml: text/plain; charset=us-ascii` encoding. I checked this by running `file -i pubspec.yaml` on all the yaml files. Is there a way to ensure that the encoding is the same using DockerFile instructions? Would this be useful? https://stackoverflow.com/questions/50564353/file-charset-changes-to-binary-in-docker-container – Guilherme Vieira Feb 01 '23 at 11:08
  • This should be utf-8 – Alexander Farkas Feb 06 '23 at 08:09
  • A null check operator error should never occur. This is a bug in either `package:pubspec` or Melos (which could be using the package incorrectly), and can be reported accordingly. – hacker1024 Apr 10 '23 at 04:10

0 Answers0