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

import 'dart:js'; error #130

Closed
sambitraze opened this issue Feb 20, 2021 · 17 comments
Closed

import 'dart:js'; error #130

sambitraze opened this issue Feb 20, 2021 · 17 comments

Comments

@sambitraze
Copy link

Description

import 'dart:js';
.pub-cache/hosted/pub.dartlang.org/razorpay_flutter-1.2.4/lib/razorpay_flutter.dart:1:8: Error: Not found: 'dart:js'

Flutter Version :

1.22.6

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

1.install razorpay-flutter and do flutter pub get
2.start flutter run

Expected Results

/C:/SDKs/flutters/.pub-cache/hosted/pub.dartlang.org/razorpay_flutter-1.2.4/lib/razorpay_flutter.dart:1:8: Error: Not found: 'dart:js'
import 'dart:js';
^
/C:/SDKs/flutters/.pub-cache/hosted/pub.dartlang.org/razorpay_flutter-1.2.4/lib/razorpay_flutter.dart:91:29: Error: The getter 'context' isn't defined for the class 'Razorpay'.

  • 'Razorpay' is from 'package:razorpay_flutter/razorpay_flutter.dart' ('/C:/SDKs/flutters/.pub-cache/hosted/pub.dartlang.org/razorpay_flutter-1.2.4/lib/razorpay_flutter.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'context'.
    _eventEmitter.on(event, context, cb);
    ^^^^^^^
    U
    nhandled exception:
    FileSystemException(uri=org-dartlang-un
    translatable-uri:dart%3Ajs; message=StandardFileSystem only supports file:* and data:* URIs)
    #0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
    Initial release #1 asFileUri (package:vm/kernel_front_end.dart:657:37)
    Update commit hash for v1.0.0-alpha #2 writeDepfile (package:vm/kernel_front_end.dart:825:21)
#3 FrontendCompiler.compile (package:frontend_se rver/frontend_server.dart:572:15) #4 _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:43:22) #5 starter (package:flutter_frontend_server/server.dart:182:27) #6 main (file:///C:/b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:9:30) #7 _startIsolate. (dart:isolate-patch/isolate_patch.dart:299:32) #8 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

FAILURE: Build failed with an exception.

  • Where:
    Script 'C:\SDKs\flutters\packages\flutter_tools\gradle\flutter.gradle' line: 904

  • What went wrong:
    Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'C:\SDKs\flutters\bin\flutter.bat'' finished with non-zero exit value 1

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 18s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 19.0s
Exception: Gradle task assembleDebug failed with exit code 1

Flutter Doctor -v

D:\fad>flutters doctor -v
[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.804], locale en-IN)
• Flutter version 1.22.6 at C:\SDKs\flutters
• Framework revision 9b2d32b605 (4 weeks ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\sambitraze\AppData\Local\Android\Sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = C:\Users\sambitraze\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[!] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.53.2)
• VS Code at C:\Users\sambitraze\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.19.0

[√] Connected device (1 available)
• Redmi Note 8 Pro (mobile) • 192.168.1.101:5555 • android-arm64 • Android 10 (API 29)

! Doctor found issues in 1 category.

@MeTubeapp
Copy link

same problem i am facing.if you find any idea how to correct this please let me know

@thelazyindian
Copy link

thelazyindian commented Feb 22, 2021

Use this for now, the recent updates to this package on its pub.dev deployment has issues so until it's fixed this will work.
@MeTubeapp @sambitraze
Add this to pubspec.yaml instead of the usual way which fetches from pub.dev
PS:- use proper indents

razorpay_flutter:
git:
url: git://github.com/razorpay/razorpay-flutter.git
ref: master

@sambitraze
Copy link
Author

image

@sambitraze
Copy link
Author

Thanks for helping us out.

@nsangwan
Copy link

Perhaps worth not closing the issue till its resolved properly.
I'd like to upvote the issue.

@sambitraze sambitraze reopened this Feb 22, 2021
@dev-chetan
Copy link

Error output from Xcode build:

** BUILD FAILED **

Xcode's output:

/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:44:1: error: unknown attribute '_hasMissingDesignatedInitializers'
@_hasMissingDesignatedInitializers @objc public class PluginPaymentModel : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:51:41: error: unknown attribute '_hasMissingDesignatedInitializers'
@objc @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers public class Otpelf : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:51:7: error: unknown attribute '_inheritsConvenienceInitializers'
@objc @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers public class Otpelf : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:59:35: error: unknown attribute '_hasMissingDesignatedInitializers'
@_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers @objc final public class RazorpayCheckout : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:59:1: error: unknown attribute '_inheritsConvenienceInitializers'
@_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers @objc final public class RazorpayCheckout : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterSdk/flutter/.pub-cache/git/razorpay-flutter-563ec01946cc8e9075929677fdf96629b69f5945/ios/Classes/RazorpayDelegate.swift:2:8: error: failed to load module 'Razorpay'
import Razorpay
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:44:1: error: unknown attribute '_hasMissingDesignatedInitializers'
@_hasMissingDesignatedInitializers @objc public class PluginPaymentModel : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:51:41: error: unknown attribute '_hasMissingDesignatedInitializers'
@objc @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers public class Otpelf : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:51:7: error: unknown attribute '_inheritsConvenienceInitializers'
@objc @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers public class Otpelf : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:59:35: error: unknown attribute '_hasMissingDesignatedInitializers'
@_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers @objc final public class RazorpayCheckout : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterProjects/flu-krutech-farmer/ios/Pods/razorpay-pod/Pod/Razorpay.framework/Modules/Razorpay.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:59:1: error: unknown attribute '_inheritsConvenienceInitializers'
@_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers @objc final public class RazorpayCheckout : ObjectiveC.NSObject {
^
/Users/multipz/Documents/FlutterSdk/flutter/.pub-cache/git/razorpay-flutter-563ec01946cc8e9075929677fdf96629b69f5945/ios/Classes/RazorpayDelegate.swift:2:8: error: failed to load module 'Razorpay'
import Razorpay
^
note: Using new build system
note: Planning build
note: Constructing build description

@thelazyindian I'm getting this issue after implementing above solution

@beingentangled
Copy link

beingentangled commented Feb 23, 2021

I'm getting the same error:

razorpay_flutter.dart:1:8: Error: Not found: 'dart:js'

@MeTubeapp
Copy link

razorpay_flutter:
git:
url: git://github.com/razorpay/razorpay-flutter.git
ref: master

add this in your pubsec mine problem is solved if cannot work for you
use this

razorpay_flutter:
git:
url: git://github.com/razorpay/razorpay-flutter.git
ref: v1.2.3

@LOG-TAG
Copy link

LOG-TAG commented Feb 23, 2021

@MeTubeapp why I'm getting this error xcode 11.3.1

Razorpay.framework/Modules/Razorpay.swiftmodule/arm64-apple-ios.swiftinterface:51:7: error: unknown attribute '_inheritsConvenienceInitializers'
    @objc @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers public class Otpelf : ObjectiveC.NSObject {

razorpay_flutter:
git:
url: git://github.com/razorpay/razorpay-flutter.git
ref: v1.2.3

@dev-chetan
Copy link

@MeTubeapp I am still facing the same error as @LOG-TAG mentioned in an above comment.

@sanjaymajoka
Copy link

sanjaymajoka commented Feb 24, 2021

Same issue after updating to razorpay_flutter: ^1.2.4
After that I downgraded to 1.2.3 as razorpay_flutter: ^1.2.3
But still faced same issue even flutter clean, deleting cache and invalidating android studio
At last I just removed ^ form version name and used as:
razorpay_flutter: 1.2.3 and Its Worked.
Downgrade is not a solution but it helped me because I was stuck in issue.

@nsangwan
Copy link

Please upvote the original issue if you'd like it to be fixed.

@sasielle
Copy link

paste this code in your razorpay_flutter.dart

import 'package:flutter/services.dart';

import 'package:eventify/eventify.dart';

class Razorpay {
// Response codes from platform
static const _CODE_PAYMENT_SUCCESS = 0;
static const _CODE_PAYMENT_ERROR = 1;
static const _CODE_PAYMENT_EXTERNAL_WALLET = 2;

// Event names
static const EVENT_PAYMENT_SUCCESS = 'payment.success';
static const EVENT_PAYMENT_ERROR = 'payment.error';
static const EVENT_EXTERNAL_WALLET = 'payment.external_wallet';

// Payment error codes
static const NETWORK_ERROR = 0;
static const INVALID_OPTIONS = 1;
static const PAYMENT_CANCELLED = 2;
static const TLS_ERROR = 3;
static const INCOMPATIBLE_PLUGIN = 4;
static const UNKNOWN_ERROR = 100;

static const MethodChannel _channel = const MethodChannel('razorpay_flutter');

// EventEmitter instance used for communication
EventEmitter _eventEmitter;

Razorpay() {
_eventEmitter = new EventEmitter();
}

/// Opens Razorpay checkout
void open(Map<String, dynamic> options) async {
Map<String, dynamic> validationResult = _validateOptions(options);

if (!validationResult['success']) {
  _handleResult({
    'type': _CODE_PAYMENT_ERROR,
    'data': {
      'code': INVALID_OPTIONS,
      'message': validationResult['message']
    }
  });
  return;
}

var response = await _channel.invokeMethod('open', options);
_handleResult(response);

}

/// Handles checkout response from platform
void _handleResult(Map<dynamic, dynamic> response) {
String eventName;
Map<dynamic, dynamic> data = response["data"];

dynamic payload;

switch (response['type']) {
  case _CODE_PAYMENT_SUCCESS:
    eventName = EVENT_PAYMENT_SUCCESS;
    payload = PaymentSuccessResponse.fromMap(data);
    break;

  case _CODE_PAYMENT_ERROR:
    eventName = EVENT_PAYMENT_ERROR;
    payload = PaymentFailureResponse.fromMap(data);
    break;

  case _CODE_PAYMENT_EXTERNAL_WALLET:
    eventName = EVENT_EXTERNAL_WALLET;
    payload = ExternalWalletResponse.fromMap(data);
    break;

  default:
    eventName = 'error';
    payload =
        PaymentFailureResponse(UNKNOWN_ERROR, 'An unknown error occurred.');
}

_eventEmitter.emit(eventName, null, payload);

}

/// Registers event listeners for payment events
void on(String event, Function handler) {
EventCallback cb = (event, cont) {
handler(event.eventData);
};
_eventEmitter.on(event, null, cb);
_resync();
}

/// Clears all event listeners
void clear() {
_eventEmitter.clear();
}

/// Retrieves lost responses from platform
void _resync() async {
var response = await _channel.invokeMethod('resync');
if (response != null) {
_handleResult(response);
}
}

/// Validate payment options
static Map<String, dynamic> _validateOptions(Map<String, dynamic> options) {
var key = options['key'];
if (key == null) {
return {
'success': false,
'message': 'Key is required. Please check if key is present in options.'
};
}
return {'success': true};
}
}

class PaymentSuccessResponse {
String paymentId;
String orderId;
String signature;

PaymentSuccessResponse(this.paymentId, this.orderId, this.signature);

static PaymentSuccessResponse fromMap(Map<dynamic, dynamic> map) {
String paymentId = map["razorpay_payment_id"];
String signature = map["razorpay_signature"];
String orderId = map["razorpay_order_id"];

return new PaymentSuccessResponse(paymentId, orderId, signature);

}
}

class PaymentFailureResponse {
int code;
String message;

PaymentFailureResponse(this.code, this.message);

static PaymentFailureResponse fromMap(Map<dynamic, dynamic> map) {
var code = map["code"] as int;
var message = map["message"] as String;
return new PaymentFailureResponse(code, message);
}
}

class ExternalWalletResponse {
String walletName;

ExternalWalletResponse(this.walletName);

static ExternalWalletResponse fromMap(Map<dynamic, dynamic> map) {
var walletName = map["external_wallet"] as String;
return new ExternalWalletResponse(walletName);
}
}

@nsangwan
Copy link

Fixing razorpay-flutter to 1.2.3 worked for me.

@Nautiyalsachin
Copy link
Contributor

Hi everyone, I would ask you guys to update to the latest plugin, we have rolled out some fixes. Also I would suggest you to update your cocoa pods so that you can get the latest Razorpay frameworks.

@sambitraze
Copy link
Author

sambitraze commented Mar 1, 2021

I have used the latest one only it was causing the above issue .. temporary solution is also given above #130 (comment)

@MeTubeapp
Copy link

MeTubeapp commented Mar 1, 2021

First time when i used latest version i m also faced import js problem. then after i done some manual work like goto the flutter.pub-cache\hosted\pub.dartlang.org path and delete the latest version file [ razorpay_flutter-1.2.4 ]. and then i used flutter clean command.and again run my app without the razorpay package because of confirmation like my app project is work or not if i am not used razorpay package.and remove razorpay related code for temporarily. after confirmation i used razorpay package from git by used these.
razorpay_flutter:
git:
url: git://github.com/razorpay/razorpay-flutter.git
ref: master

if this not work please make a new project and again used razorpay package bt add these lines

razorpay_flutter:
git:
url: git://github.com/razorpay/razorpay-flutter.git
ref: master

after this procedure my app is working fine with latest razorpay package .

notei make app only for android not for ios.

i dont know this solution work for ios .

i hope this work for all.

Jai Shree Ram.

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

No branches or pull requests

10 participants