EddyVerbruggen / nativescript-nodeify

Makes most npm packages compatible with NativeScript
MIT License
93 stars 27 forks source link

invalid arguments - $platformsData #65

Open Zoey-rahimi opened 5 years ago

Zoey-rahimi commented 5 years ago

I'm trying to use Forge in the native script project and in a regular way it does not work, so I decided to use this module to make it work. And now I m getting this error:

hooks\after-prepare\nativescript-nodeify.js will NOT be executed because it has invalid arguments - $platformsData.

it seems in the patch-platforms.js file it can not recognise this argument.

Falu-G commented 4 years ago

I am having this exact same issue. Kindly help pls.

EddyVerbruggen commented 4 years ago

That hook needs to be rewritten a little for NativeScript 6. See this doc.

There are loads of examples (other plugins) around, so if anyone wants to submit a PR that would be great!

Falu-G commented 4 years ago

@EddyVerbruggen I have just modified the hooks and am getting Cannot find module ..\platforms\android\app\src\main\assets\app\tns_modules\nativescript-nodeify\patch-npm-packages.js' please any workaround from here. Kindly assist.

Falu-G commented 4 years ago

I just tried the apporoach in issue #35 and i got this

[19-10-02 17:50:19.369] (CLI) ERROR in ../node_modules/readable-stream/lib/_stream_readable.js [19-10-02 17:50:19.369] (CLI) Module not found: Error: Recursion in resolving

@EddyVerbruggen Kindly assist

francoisph commented 4 years ago

I've updated patch-platforms.js for NS6 :

module.exports = function ($logger, $projectData, $injector, hookArgs) {
    var path = require('path');
    var platformName = (hookArgs.checkForChangesOpts && hookArgs.checkForChangesOpts.platform) || (hookArgs.prepareData && hookArgs.prepareData.platform);
    const platformsData = getPlatformsData($injector);

var appDestinationDir = platformsData.getPlatformData(platformName).appDestinationDirectoryPath;

    var patchNpmPackageDir = path.join(appDestinationDir, 'app', 'tns_modules', 'nativescript-nodeify', 'patch-npm-packages.js');

    var patchNpmPackage = require(patchNpmPackageDir);

    patchNpmPackage($logger, $projectData, hookArgs);
}

function getPlatformsData($injector) {
    try {
        return $injector.resolve("platformsData");
    } catch (err) {
        return $injector.resolve("platformsDataService");
    }
}

But I have same issues as you : ERROR in ../node_modules/readable-stream/lib/_stream_readable.js I didn't find a good solution to run nativescript-nodeify with webpack...

I found a hack but it will modify your YOUR_PROJECT_ROOT/node_modules and I'm not sure that in the spirit of webpack. In patch-platforms.js remplace : var patchNpmPackage = require(patchNpmPackageDir); by var patchNpmPackage = require("./patch-npm-packages.js");

Then in my project, I just want to nodeify the module 'aws-sdk' so instead to have a blacklist in patch-npm-packages.js I have a whitelist which modify just the modules that I want : var whitelist = ["aws-sdk"]

Delete : if (!changesInfo.modulesChanged) { return; } and if (blacklist.indexOf(file.name) > -1) { return; } Remplace blacklist.indexOf(file.name) > -1 by whitelist.indexOf(file.name) == -1 Remplace blacklist.indexOf(folderName) === -1 by whitelist.indexOf(folderName) > -1

I can build and push my app on android/ios phone and everything seems to work.

nirmay commented 4 years ago

I am trying to get nativescript-nodeify working for aws-amplify and I am hitting the same issue discussed here. I tried the the notes added by @francoisph, but cannot get the plugin fired. I forked this repo, made changes suggested in the previous post, and installed the custom plugin. The installation seems to work, the error reported earlier "nativescript-nodeify.js will NOT be executed because it has invalid arguments - $platformsData." is also gone, however, still get the child_process, crypto related build/runtime errors.

How do I debug this further? @EddyVerbruggen any help would be appreciated.

My change is breathing here - https://github.com/nirmay/nativescript-nodeify/commit/01ebf173e8bb61a84655f51f782852eb0d3bb430

ineiti commented 4 years ago

Continuing going down that rabbit hole. Another problem is that prior to NS6, you had a different workflow where all the content of node_modules was copied to platforms/.../app/src/main/assets/app/tns_modules, which is not the case anymore with the NS6 webpack workflow. I don't know yet how to best work around this.

My first try will be to do the replacement directly in the node_modules directory. But I have a bad feeling about this.

ineiti commented 4 years ago

The cleanest way for this to work would probably be to add it as a webpack-plugin. But that seems like a big rewrite, which I'm not eager to do...

ineiti commented 4 years ago

So for me currently this means:

Niach commented 4 years ago

I managed to get tweetnacl.js working in tns6. It only needed crypto.getRandomValues() to be implemented and i shimmed it using webpack: https://stackoverflow.com/questions/53172766/how-to-use-ripple-lib-with-nativescript/53925032#53925032 Just FYI if someone stumbles upon the same issue