Error building cordova project

Has anyone encountered this issue while using Meteor Cordova for Android or iOS?

My project is running Meteor v2.16, which uses Node.js v14.21.3. I tried switching to Node.js v16.20, but the same error persists. I’ve also cleared the cache, removed cordova-build, and retried, but the issue remains. Any suggestions?

6 Likes

We are having the same issue, also in Meteor 2.16, which requires Node 14. However, cordova-common@5.0.1 was published a few days ago, and it requires Node 16. This is a dependency of Cordova, not Meteor.

Any idea how to force the installation of cordova-common@5.0.0, which is compatible with Node 14?

We added it to the cordova-build-override folder, but after running the meteor build command, the changes get overwritten.

2 Likes

Tried the same here! :frowning:

Have you tried fixing the cordova-common 5.0.0 version directly in the auto-generated Cordova project within .meteor/local/cordova-build/package.json? Maybe reapplying a npm install there afterwards.

If this works, you might need a script to reapply the fix after clearing the .meteor/local cache.

Let me know if it works.

1 Like

Under meteor-tools/2.16/tools/cordova/index.js it references it as 4.0.2
const CORDOVA_DEV_BUNDLE_VERSIONS = {
‘cordova-lib’: ‘10.0.0’,
‘cordova-common’: ‘4.0.2’,
‘cordova-create’: ‘2.0.0’,
‘cordova-registry-mapper’: ‘1.1.15’,
‘cordova-android’: CORDOVA_ANDROID_VERSION
};

It almost seems like its not referencing the version number and just installing the latest.

Update:
Cordova-android npm-package has 5+ as a dependancy
“dependencies”: {
“cordova-common”: “^5.0.0”
}

I have issues a compatibility bug report on Cordova-common

Well they are unwilling to change it, so well have to work other method:

created a bypass function, have to reset, let it fail first then add the function to continue to run.

app/.meteor/local/cordova-build/node_modules/cordova-common/src/FileUpdater.js

function copyRecursiveSync(source, target) {
  // Resolve the paths inside the function
  const resolvedSource = path.resolve(source);
  const resolvedTarget = path.resolve(target);
  const stats = fs.statSync(resolvedSource);
  if (stats.isDirectory()) {
    if (!fs.existsSync(resolvedTarget)) {
      fs.mkdirSync(resolvedTarget, { recursive: true });
    }
    const files = fs.readdirSync(resolvedSource);
    files.forEach(file => {
      const srcPath = path.join(resolvedSource, file);
      const destPath = path.join(resolvedTarget, file);
      copyRecursiveSync(srcPath, destPath);
    });
  } else {
    const parentDir = path.dirname(resolvedTarget);
    if (!fs.existsSync(parentDir)) {
      fs.mkdirSync(parentDir, { recursive: true });
    }
    fs.copyFileSync(resolvedSource, resolvedTarget);
  }
}
copyRecursiveSync(path.join(rootDir, sourcePath), targetFullPath);

// fs.cpSync(path.join(rootDir, sourcePath), targetFullPath, { recursive: true });
copyRecursiveSync(path.join(rootDir, sourcePath), targetFullPath);
2 Likes

Hopefully, your bypass function @wadebuildotto is helping others unblock their setups.

What I’d like to try is to force a specific dependency version, even for transitive ones. Have you tried using resolutions in Yarn or npm-force-resolutions with NPM? Newer NPM versions have overrides enabled, but Node 14.x doesn’t come with that NPM version.

Using something like this might let you force a dependency fix:

"resolutions": {  
  "cordova-common": "5.0.0"  
}  

You’ll need to add this to .meteor/local/cordova-build/package.json and reinstall the dependencies. Again, if this works might require a script for you to save your time each time you clear the cordova context.

Can anyone try this? If I get some time, I’ll test this. If this is a working approach we may introduce a fix for 2.x. This seems to be a sudden issue for all Meteor 2.x users, which might be important.

A workaround solution

@wadebuildotto’s suggestion is a workable approach, so try that. To make it easier, I’ve prepared a script for UNIX-like systems:

curl -o .meteor/local/cordova-build/node_modules/cordova-common/src/FileUpdater.js https://gist.githubusercontent.com/nachocodoner/f05359529b8d0f9899051cb7c85d9f78/raw/e2a48d7802423d3ad4d36897c48dd6a6377447d4/FileUpdater.js

Run this in the root of your Meteor app after encountering the error for the first time, as mentioned. If you clean .meteor/local, you’ll likely need to run it again.


Apart from that testing, I spent some time looking for a fix for this issue. It’s true that the cordova-build context in 2.16 (at least initially) doesn’t include a package.json file to use the resolutions strategy. I tried using resolutions, but it didn’t work as expected.

I could have tested more, but I decided to try it directly in the Meteor core. While debugging, I ran into some issues but haven’t found a quick solution yet.

I’ll discuss this with the team as this seems critical for Meteor 2.14 onward users, but I want to clarify a few things. In Meteor 2.x, we were limited by Node 14. To address Cordova issues (e.g., newer SDK requirements), Meteor upgraded Cordova to the latest versions, which require Node 16+. These upgrades worked well until now.

The sudden issue is due to a patch applied to a library used by Meteor 2.x directly and indirectly through other Cordova dependencies. Since the library targets Node 16, it uses a newer API on the patch. The challenge with a patch is that it installs the latest version automatically unless pinned, which isn’t a straightforward task at least so far.

Meteor 3 avoids these issues, making migration to the latest version essential, even though it can be challenging. Similar issues may arise in the future.

4 Likes

Thank you for the detailed explanation and for providing the script! It’s really helpful to have a quick workaround while we deal with this issue. I really appreciate the time and effort you put into investigating this issue and preparing a fix. Looking forward to any further updates from the team.

2 Likes

We’ve prepared a branch fixing the issue on Cordova platforms by forcing to use cordova-common@5.0.0 version. This should resolve the problem. We’ll publish a 2.16.1-beta version so you can test it in your real environments. I’ll let you know when the beta is ready. We will need your feedback.

Meanwhile, you can use the workaround script above or apply the PR changes if using a Meteor checkout.

2 Likes

Meteor 2.16.1-beta.0 is live with the fix for this issue.

I need help testing it in production apps. Can you assist?

Run meteor update --release 2.16.1-beta.0 to update your apps.

If verified, I’ll release 2.16.1 officially. Thanks!

2 Likes