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