Build error on a fresh Ubuntu 24.04

Hello,

I am preparing a MakeCode and its variants locally on my Ubuntu 24.04 box in Japanese for my kids and their friends.

I have just followed the Build instruction, but failed as follows.

~/projects/pxt$ node --version
v18.19.1
~/projects/pxt$ npm --version
9.2.0
~/projects/pxt$ npm install
...
Installing authcode...
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/tsato/projects/pxt/built/react-common/components/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/tsato/projects/pxt/built/react-common/components/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
...
~/projects/pxt$ grep react-common authcode/package.json 
    "react-common": "file:../built/react-common/components",

There is no such a folder called “built” at this point.

I checked the change history of authcode/package.json. But it has been 2 years since the last change. Is there any command I should do before running npm install?

Regardless of this specific issue, there is a chicken-egg situation here. built folder is referenced by a module to be installed. But built folder is created by gulp. Yet, gulp can not be run without running npm install first because it requires local modules.

So, here’s the procedure to build a bit ugly but successfully.

  1. pxt$ sudo npm install gulp
  2. pxt$ npm install
    • this will fail because of the same error as I reported because no built folder exists
  3. pxt$ git apply gulp_patch.diff
    • see below for the detail
  4. pxt$ gulp
    • this will build TypeScript files but fail becuase not enough modules exist, yet
  5. pxt$ npm install
    • this will succeed
  6. pxt$ gulp
    • this will suceed
  7. pxt$ gulp test
    • only karma fails

The patch contains a code snippet that used to generate a dummy package.json, which was removed sometime ago. Also, karma is commented out.

pxt$ cat gulp_patch.diff 
diff --git a/gulpfile.js b/gulpfile.js
index 1abd2b131..071509759 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -50,6 +50,21 @@ const reactCommon = () => compileTsProject("react-common", "built/react-common",
 const pxtblocks = () => compileTsProject("pxtblocks", "built/pxtblocks", true);
 const pxtservices = () => compileTsProject("pxtservices", "built/pxtservices", true);
 
+// We output a dummy package.json in the built react-common directory to prevent
+// npm from complaining when we npm install in the skillmap and authcode
+const reactCommonPackageJson = () => {
+    fs.writeFileSync(path.resolve("built/react-common/components/package.json"), `
+    {
+        "name": "react-common",
+        "description": "",
+        "version": "0.0.0",
+        "dependencies": {},
+        "devDependencies": {}
+    }
+    `)
+    return Promise.resolve();
+}
+
 const pxtapp = () => gulp.src([
     "node_modules/lzma/src/lzma_worker-min.js",
     "node_modules/dompurify/dist/purify.min.js",
@@ -673,7 +688,7 @@ const testAll = gulp.series(
     testpytraces,
     testtutorials,
     testlanguageservice,
-    karma,
+    //karma,
     testSkillmap,
     testpxteditor
 )
@@ -739,6 +754,7 @@ const buildAll = gulp.series(
     gulp.parallel(pxtjs, pxtdts, pxtapp, pxtworker, pxtembed),
     targetjs,
     reactCommon,
+    reactCommonPackageJson,
     gulp.parallel(buildcss, buildSVGIcons),
     maybeBuildWebapps(),
     webapp,