# Error when calling canister method from React app

**URL:** <https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914>\
**Category:** Developers\
**Created:** [September 2, 2021, 1:38pm UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914 "2021-09-02T13:38:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hayatonagasaki](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hayatonagasaki](https://forum.dfinity.org/u/hayatonagasaki)\
**Post date:** [September 2, 2021, 1:38pm UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/1 "2021-09-02T13:38:30Z")

</div>

Hello  
I’m developing an application locally using ReactJS, but got the following error.

```auto
Unhandled Rejection (Error): Impossible to convert undefined to Principal.

```

Can anyone help me with this?

---

<div class="post-metadata">

**Author:** ![CarstenJ](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/carstenj/32/2729_2.png) [@CarstenJ](https://forum.dfinity.org/u/CarstenJ)\
**Post date:** [September 2, 2021, 4:17pm UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/2 "2021-09-02T16:17:26Z")

</div>

Hello,

Can you please provide a bit more information about what you are trying to do? Are you working with Internet Identity?

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [September 2, 2021, 4:21pm UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/3 "2021-09-02T16:21:43Z")

</div>

9 times out of 10, for this error, you are passing an undefined canister ID to the `createActor` method. Check your webpack config

---

<div class="post-metadata">

**Author:** ![hayatonagasaki](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hayatonagasaki](https://forum.dfinity.org/u/hayatonagasaki)\
**Post date:** [September 3, 2021, 1:44am UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/4 "2021-09-03T01:44:16Z")

</div>

Thank you for replying!

I’m working for a private project using React and the Internet Computer, but got the error.

So I’m now trying to figure out what causes this error and working with a very simple react app which I just followed [the Create New React App](https://reactjs.org/docs/create-a-new-react-app.html) document.  
But, even the simple react app, I’m getting the same error.

I started IC project with the command below

```auto
dfx new dfx_react_app

```

and started react app on another directory.

```auto
npx create-react-app my-app

```

Then, I copied the files from “src” and whole public directory from the react app and pasted to dfx\_react\_app directory.

It seems like configuration settings somewhere don’t match each other.  
Or do I need to do something else in order to work on both IC and React?

> **[GitHub - linkremix2021/dfx\_react\_app](https://github.com/linkremix2021/dfx_react_app)**
>
> Contribute to linkremix2021/dfx\_react\_app development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![hayatonagasaki](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hayatonagasaki](https://forum.dfinity.org/u/hayatonagasaki)\
**Post date:** [September 3, 2021, 1:49am UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/5 "2021-09-03T01:49:53Z")

</div>

@anon74414410  
I just checked the webpack.config.js now and remembered that I changed the canister name.

When I launched new dfx project, there were canisters “dfx\_react\_app” and “dfx\_react\_app\_assets”. But I changed to “service” and “frontend” in dfx.json file.

Does webpack.config.js cause the error?

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [September 3, 2021, 1:57am UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/6 "2021-09-03T01:57:08Z")

</div>

It’s just preconfigured to hope to spare you needing to modify it. Check the EnvironmentPlugin and make sure it reflects your new canister name

---

<div class="post-metadata">

**Author:** ![rckprtr](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rckprtr/32/809_2.png) [@rckprtr](https://forum.dfinity.org/u/rckprtr)\
**Post date:** [September 6, 2021, 3:10am UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/9 "2021-09-06T03:10:40Z")

</div>

Great timing on this 🙂

---

<div class="post-metadata">

**Author:** ![tommccann](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tommccann/32/19421_2.png) [@tommccann](https://forum.dfinity.org/u/tommccann)\
**Post date:** [November 14, 2021, 12:24am UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/10 "2021-11-14T00:24:38Z")

</div>

Hi @kpeacock , I’m suffering the same problem. Is there advice anywhere on what should be in the webpack config to ensure the canisterId gets passed to the createActor method?

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [November 14, 2021, 1:12am UTC](https://forum.dfinity.org/t/error-when-calling-canister-method-from-react-app/6914/11 "2021-11-14T01:12:52Z")

</div>

You can pass the canister id manually as a string or Principal, or you should make sure that Webpack is setting up the EnvironmentPlugin with your canister correctly, matching the process.env variable in your generated index.js.

I’ve also simplified the configuration for the next version of dfx, so there should be less configuration in new projects once it goes out
