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

Restricted in strict mode, js engine: hermes (React Native + Axios 1.0.0) #4998

Closed
tapz opened this issue Oct 4, 2022 · 50 comments · Fixed by #5224
Closed

Restricted in strict mode, js engine: hermes (React Native + Axios 1.0.0) #4998

tapz opened this issue Oct 4, 2022 · 50 comments · Fixed by #5224

Comments

@tapz
Copy link

tapz commented Oct 4, 2022

Describe the bug

Getting an error with React Native when importing a function from a file, which uses Axios.

Error: Requiring module "src/api/Api.js", which threw an exception: TypeError: Restricted in strict mode, js engine: hermes

To Reproduce

Import a function.

import { logout } from './api/Api';

---

export function logout() {
  return axios.put(endPoint, body, {
      headers: {
        ...Headers,
        ...headers
      }
    });
}

Expected behavior

No errors

Environment

  • Axios Version: 1.0.0
  • Node.js Version: 16
  • OS: MacOS
  • Additional Library Versions: React Native 0.70.2

Additional context/Screenshots

Add any other context about the problem here. If applicable, add screenshots to help explain.

@tapz tapz changed the title 1.0.0: Restricted in strict mode, js engine: hermes Restricted in strict mode, js engine: hermes (React Native + Axios 1.0.0) Oct 4, 2022
@ManishBitsInfotech
Copy link

i have the same issue in my new react native project please let me know if there is any solution for the same

@akachi1409
Copy link

I have the same issue here.

@hikmert
Copy link

hikmert commented Oct 5, 2022

It's same here with a new React-native project. It doesn't allow any JS files although I set allowJs to true in tsconfig.json

@ManishBitsInfotech
Copy link

What is the solution for this

@uasad1099
Copy link

lower axios version worked for me - axios:'0.26.0'

@grandevel
Copy link

Same issue, 3 different RN projects with 1.0.0. All projects use axios interceptors in some form. Downgraded to 0.27.2, working fine again.

@ManishBitsInfotech
Copy link

I have downgrade the axios version for this issue
https://www.npmjs.com/package/axios/v/0.26.0

and also add this line in my api call for use formData

axios.post(url, formData, {
headers: { 'Content-Type': 'multipart/form-data' },
transformRequest: formData => formData, // this line
})

i hope this will work for you too guys

@hikmert
Copy link

hikmert commented Oct 6, 2022

Downgrading Axios resolved the issue for me.

@jrobinsonadrenaline
Copy link

jrobinsonadrenaline commented Oct 6, 2022

Same issue here, as well as the same solution - downgrade to v0.26.0

@am2619015
Copy link

Same issue here on axios 1.1.0, let's hope there's another solution to the downgrade

@am2619015
Copy link

Had this issue with axios 1.1.2 in react native and was able to resolve it by replacing

import axios from 'axios' with const axios = require('axios').default;

I just tried it, it didn't work for me, the same error message keeps popping up "TypeError: Restricted in strict mode, js engine: hermes" besides a new one "[TypeError: Cannot read property 'default' of undefined]"

"axios": "^1.1.2",
"react": "18.1.0",
"react-native": "0.70.2",

@ManishBitsInfotech
Copy link

ManishBitsInfotech commented Oct 8, 2022 via email

@am2619015
Copy link

i have posted the solution for same please check it out

On Sat, 8 Oct, 2022, 11:35 pm ANDRES MADERA, @.> wrote: Had this issue with axios 1.1.2 in react native and was able to resolve it by replacing import axios from 'axios' with const axios = require('axios').default; I just tried it, it didn't work for me, the same error message keeps popping up "TypeError: Restricted in strict mode, js engine: hermes" besides a new one "[TypeError: Cannot read property 'default' of undefined]" "axios": "^1.1.2", "react": "18.1.0", "react-native": "0.70.2", — Reply to this email directly, view it on GitHub <#4998 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3N4L33SDVYGELOFFS36TETWCGZXFANCNFSM6AAAAAAQ47XETY . You are receiving this because you commented.Message ID: @.>

Yes downgrading axios to 0.26.0 works, I hope that in a future version of axios we will not have this problem

@iamciro
Copy link

iamciro commented Oct 8, 2022

Same issue here, as mentioned by grandevel, downgrading to 0.27.2 solved it.

@tapz
Copy link
Author

tapz commented Oct 9, 2022

@ManishBitsInfotech Dowgrading is not a fix. It does not make 1.x.x work any better.

@imamrobani
Copy link

@ManishBitsInfotech Dowgrading is not a fix. It does not make 1.x.x work any better.

agree, but for now, I think if u want still using axios and the new RN version best choice is using axios 0.27.2
and wait until they fix it

@imamrobani
Copy link

solved it by downgrade axios version
downgrading to 0.27.2 solved it

@togenius1
Copy link

I got the same isssues.

@RodrigoSarmento
Copy link

We already know that it works in 0.27, though we need to know how to make it work for 1.0ˆ, no need to keep saying downgrade works.

@YounesKHENIFER
Copy link

same here

@AHMAD58198
Copy link

i downgraded axios to 0.21.4 and the issue is gone

Romick2005 added a commit to Romick2005/axios that referenced this issue Oct 18, 2022
…e to the 'caller', 'callee', and 'arguments' properties. TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode.
@Romick2005
Copy link

@jasonsaayman please review my fix and merge if it ok for you.

@jasonsaayman
Copy link
Member

Will do tonight when I do another release

@imfbi
Copy link

imfbi commented Oct 19, 2022

resolved the issue for me.

Thank you.

@buuhvprojects
Copy link

thanks this solved it to me

@hellogbg
Copy link

Will do tonight when I do another release

Have you been able to do release this?
I am not getting it to work with current version (1.1.3)

@Chandansharma1512
Copy link

Are you releasing new version?
I am not getting same issue after downgrading axios version as well.

@saadnaveed94
Copy link

i think there will be a release shortly. meanwhile using a lower version is the way to go.

@Viktor19931
Copy link

still same issue

1 similar comment
@mayfairr
Copy link

mayfairr commented Nov 3, 2022

still same issue

@osielmesa
Copy link

osielmesa commented Nov 4, 2022

This issue is making all the effort the team had made on new axios versions worthless. We are forced to use version 0.27.2 until it's fixed. Please put priority on this. If this PR solves it, please check it as soon as possible.

@natemartins
Copy link

natemartins commented Nov 4, 2022

While downgrading axios solves the issue, it is not recommended. What I did was to patch axios using @osielmesa PR.

How to patch:

  1. Make the changes according to the PR.
  2. Install patch-package if you have not already done so.
  3. Run npx patch-package axios. Note that if you have not done Step 2, you will be prompted to install patch-package

Hopefully, this resolves the issue for us while we await axios to fix it from their end or approve and merge the PR

@moustaouiSalaheddine
Copy link

Downgrading to Axios 0.27.2 resolved the issue for me.

"axios": "0.27.2"

@Uzef1997
Copy link

Uzef1997 commented Nov 9, 2022

Still getting the same issue in 1.1.3 version of axios any leads on that except downgrading the version

@Simba-Mupfunya
Copy link

We are all waiting for the next release as it seems to be fixed in #5224. Only sure way for now unit then is to downgrade to 0.27.2, I saw somebody mention a patch but best to keep an eye on the releases

@thiago-albuquerque
Copy link

npm uninstall axios => npm install axios@0.27.2 => uninstall your app and then re-install.

@jasonsaayman
Copy link
Member

Hi 👋

Please try the latest pre-release by running the following:

npm i axios@1.2.0-alpha.1

Please provide feedback in either the pinned issue or discussion thread 🧵

@benomzn
Copy link

benomzn commented Nov 10, 2022

Hi 👋

Please try the latest pre-release by running the following:

npm i axios@1.2.0-alpha.1

Please provide feedback in either the pinned issue or discussion thread 🧵

Hi bro, i just installed this version, it works !

@krendus
Copy link

krendus commented Nov 13, 2022

Hi wave

Please try the latest pre-release by running the following:

npm i axios@1.2.0-alpha.1

Please provide feedback in either the pinned issue or discussion thread thread

this worked for me too thanks

@nelsonVE
Copy link

Works like a charm, thank you

@jrobinsonadrenaline
Copy link

Hi 👋

Please try the latest pre-release by running the following:

npm i axios@1.2.0-alpha.1

Please provide feedback in either the pinned issue or discussion thread 🧵

Works perfect for me! Thanks!

hstandaert added a commit to cultuurnet/uitpas-mobile-app that referenced this issue Nov 15, 2022
As seen in axios/axios#4998 (comment), axios causes an error in the latest RN version, therefor we need to upgrade to the most recent beta version for it to work.
@bombillazo
Copy link

bombillazo commented Nov 15, 2022

Seems this is still causing issues with React Native : facebook/react-native#34688

UPDATE

npm i axios@1.2.0-alpha.1

This fixed it for me.

@DigitalBrainJS
Copy link
Collaborator

@bombillazo There doesn't seem to be anything related to Axios v1.2.0-alpha.1

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