Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid arguments - $platformsData #65

Open
Zoey-rahimi opened this issue Sep 17, 2019 · 10 comments
Open

invalid arguments - $platformsData #65

Zoey-rahimi opened this issue Sep 17, 2019 · 10 comments

Comments

@Zoey-rahimi
Copy link

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
Copy link

Falu-G commented Oct 2, 2019

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

@EddyVerbruggen
Copy link
Owner

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
Copy link

Falu-G commented Oct 2, 2019

@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
Copy link

Falu-G commented Oct 2, 2019

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
Copy link

francoisph commented Oct 2, 2019

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
Copy link

nirmay commented Oct 29, 2019

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 - nirmay@01ebf17

nirmay pushed a commit to nirmay/nativescript-nodeify that referenced this issue Oct 29, 2019
@ineiti
Copy link

ineiti commented Nov 6, 2019

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
Copy link

ineiti commented Nov 6, 2019

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
Copy link

ineiti commented Nov 6, 2019

So for me currently this means:

  • nativescript-nodeify with --bundle is out of reach to fix for me, so not possible with tns >= 6
  • I have no idea how people use packages including crypto in tns >= 6, so I'll stay with tns < 6...

@Niach
Copy link

Niach commented Nov 6, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants