# \[hello\_world\] Error: Failed while trying to deploy canisters

**URL:** <https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176>\
**Category:** Developers\
**Created:** [December 1, 2023, 12:06am UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176 "2023-12-01T00:06:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cell](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cell/32/14140_2.png) [@cell](https://forum.dfinity.org/u/cell)\
**Post date:** [December 1, 2023, 12:06am UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/1 "2023-12-01T00:06:26Z")

</div>

Hi everyone. I’m a newbie at programming, sorry. I am using dfx version 0.15.1, Windows 11, Ubuntu 20.04.6

When I try to locally deploy hello\_world, I keep getting this situation:

> Error: Failed while trying to deploy canisters.  
> Caused by: Failed while trying to deploy canisters.  
> Failed to build all canisters.  
> Failed while trying to build all canisters.  
> The post-build step failed for canister ‘bd3sg-teaaa-aaaaa-qaaba-cai’ (hello\_world\_frontend) with \> an embedded error: Failed to build frontend for network ‘local’.  
> “npm” “run” “build”’ failed with exit status ‘exit status: 1’.  
> Stdout:  
> hello\_world\_frontend@0.2.0 prebuild  
> dfx generate

I get the same error with the command “dfx deploy --playground”

I don’t know what to do. Please help me understand what is wrong. 🫥

---

<div class="post-metadata">

**Author:** ![NathanosDev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nathanosdev/32/7204_2.png) [@NathanosDev](https://forum.dfinity.org/u/NathanosDev)\
**Post date:** [December 1, 2023, 1:07am UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/2 "2023-12-01T01:07:04Z")

</div>

It looks like the `dfx generate` part of your build step is failing, are there any more logs below the last line that you’ve provided? If not, you can try run `dfx generate` alone to see what error pops up.

---

<div class="post-metadata">

**Author:** ![cell](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cell/32/14140_2.png) [@cell](https://forum.dfinity.org/u/cell)\
**Post date:** [December 1, 2023, 1:08pm UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/3 "2023-12-01T13:08:49Z")

</div>

Hi Nathanos! Thank you for your reply.

here’s the full picture:

 ![111](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/c/c334162aa3728272dea2cbd7d78c777222ae09f3.png)

On requesting **dfx generate** I get this result:

> Building canisters before generate for Motoko  
> Generating type declarations for canister hello\_world\_frontend:  
> src/declarations/hello\_world\_frontend/hello\_world\_frontend.did.d.ts  
> src/declarations/hello\_world\_frontend/hello\_world\_frontend.did.js  
> src/declarations/hello\_world\_frontend/hello\_world\_frontend.did  
> Generating type declarations for canister hello\_world\_backend:  
> src/declarations/hello\_world\_backend/hello\_world\_backend.did.d.ts  
> src/declarations/hello\_world\_backend/hello\_world\_backend.did.js  
> src/declarations/hello\_world\_backend/hello\_world\_backend.did

To my non-professional eye it looks quite sane and doesn’t look like a mistake.

---

<div class="post-metadata">

**Author:** ![NathanosDev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nathanosdev/32/7204_2.png) [@NathanosDev](https://forum.dfinity.org/u/NathanosDev)\
**Post date:** [December 1, 2023, 2:23pm UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/4 "2023-12-01T14:23:07Z")

</div>

Yeah it seems `dfx generate` is working correctly. I’ve never seen this error that have at the bottom of the screenshot.

Are you running these commands from the command prompt by any chance? There’s mentions of `CMD.exe` in that error.

If you’re in the standard command prompt then you’ll see your current path at the beginning of the line like this:  
`C:\Users\Username`. If that’s the case then you should run `wsl.exe` to enter the Ubuntu Bash and then you’ll see `username@hostname:/mnt/c/Users/Username` instead.

---

<div class="post-metadata">

**Author:** ![morotijani](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/morotijani/32/14163_2.png) [@morotijani](https://forum.dfinity.org/u/morotijani)\
**Post date:** [December 4, 2023, 12:05pm UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/5 "2023-12-04T12:05:36Z")

</div>

anytime i run npx azle new azle\_hello\_world  
i get these errors…

mijma@DESKTOP-NS66FFM:~/development/ic-project$ npx azle new azle\_hello\_world  
Need to install the following packages:  
azle@0.18.6  
Ok to proceed? (y) y  
npm ERR! code ENOTEMPTY  
npm ERR! syscall rename  
npm ERR! path /home/mijma/.npm/\_npx/22da3992a7cf1870/node\_modules/azle  
npm ERR! dest /home/mijma/.npm/\_npx/22da3992a7cf1870/node\_modules/.azle-3k9oa9UC  
npm ERR! errno -39  
npm ERR! ENOTEMPTY: directory not empty, rename ‘/home/mijma/.npm/\_npx/22da3992a7cf1870/node\_modules/azle’ → ‘/home/mijma/.npm/\_npx/22da3992a7cf1870/node\_modules/.azle-3k9oa9UC’

npm ERR! A complete log of this run can be found in: /home/mijma/.npm/\_logs/2023-12-04T12\_03\_54\_540Z-debug-0.log

---

<div class="post-metadata">

**Author:** ![cell](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cell/32/14140_2.png) [@cell](https://forum.dfinity.org/u/cell)\
**Post date:** [December 7, 2023, 11:15pm UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/6 "2023-12-07T23:15:19Z")

</div>

I tried it. Still an error. But this time I was able to get the log file:

0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node\_modules\npm\bin\npm-cli.js  
1 info using npm@8.19.2  
2 info using node@v18.12.1  
3 timing npm:load:whichnode Completed in 1ms  
4 timing config:load:defaults Completed in 2ms  
5 timing config:load:file:C:\Program Files\nodejs\node\_modules\npm\npmrc Completed in 7ms  
6 timing config:load:builtin Completed in 7ms  
7 timing config:load:cli Completed in 2ms  
8 timing config:load:env Completed in 1ms  
9 timing config:load:file:C:\Windows.npmrc Completed in 1ms  
10 timing config:load:project Completed in 4ms  
11 timing config:load:file:C:\Users\user.npmrc Completed in 0ms  
12 timing config:load:user Completed in 0ms  
13 timing config:load:file:C:\Users\user\AppData\Roaming\npm\etc\npmrc Completed in 0ms  
14 timing config:load:global Completed in 0ms  
15 timing config:load:validate Completed in 1ms  
16 timing config:load:credentials Completed in 1ms  
17 timing config:load:setEnvs Completed in 1ms  
18 timing config:load Completed in 19ms  
19 timing npm:load:configload Completed in 20ms  
20 timing npm:load:mkdirpcache Completed in 1ms  
21 timing npm:load:mkdirplogs Completed in 0ms  
22 verbose title npm run generate  
23 verbose argv “run” “generate”  
24 timing npm:load:setTitle Completed in 1ms  
25 timing config:load:flatten Completed in 3ms  
26 timing npm:load:display Completed in 4ms  
27 verbose logfile logs-max:10 dir:C:\Users\user\AppData\Local\npm-cache\_logs  
28 verbose logfile C:\Users\user\AppData\Local\npm-cache\_logs\2023-12-07T23\_12\_31\_048Z-debug-0.log  
29 timing npm:load:logFile Completed in 4ms  
30 timing npm:load:timers Completed in 0ms  
31 timing npm:load:configScope Completed in 0ms  
32 timing npm:load Completed in 32ms  
33 silly logfile start cleaning logs, removing 2 files  
34 timing command:run Completed in 3ms  
35 verbose stack Error: ENOENT: no such file or directory, open ‘C:\Windows\package.json’  
36 verbose cwd C:\Windows  
37 verbose Windows\_NT 10.0.22621  
38 verbose node v18.12.1  
39 verbose npm v8.19.2  
40 error code ENOENT  
41 error syscall open  
42 error path C:\Windows/package.json  
43 error errno -4058  
44 error enoent ENOENT: no such file or directory, open ‘C:\Windows\package.json’  
45 error enoent This is related to npm not being able to find a file.  
45 error enoent  
46 verbose exit -4058  
47 timing npm Completed in 49ms  
48 verbose code -4058  
49 error A complete log of this run can be found in:  
49 error C:\Users\user\AppData\Local\npm-cache\_logs\2023-12-07T23\_12\_31\_048Z-debug-0.log

---

<div class="post-metadata">

**Author:** ![NathanosDev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nathanosdev/32/7204_2.png) [@NathanosDev](https://forum.dfinity.org/u/NathanosDev)\
**Post date:** [December 7, 2023, 11:48pm UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/7 "2023-12-07T23:48:03Z")

</div>

Ah, thanks for sharing that. Now I can clearly see what the issue is. You haven’t installed NodeJS inside of WSL, so it’s delegating to the NodeJS that’s installed on Windows. That won’t work because NodeJS needs to be built differently for Windows than it does for WSL, which is running a Linux OS. You can see this is the case because of the `C:\Program Files\nodejs\node.exe` part of your log file.

You can validate it by running `whereis nodejs`, if you see a `C:\Program Files\...` path then that confirms this is the issue.

You can install NodeJS inside of WSL according to the instructions for your distribution: [Installing Node.js via package manager | Node.js](https://nodejs.org/en/download/package-manager), if you didn’t pick a specific distribution then the default is Debian / Ubuntu.

Or if you prefer, you could check a node version manager such as [nvm](https://github.com/nvm-sh/nvm), or [fnm](https://github.com/Schniz/fnm). I personally prefer fnm if you go that route and are not sure which one to choose.

After installing NodeJS, you can run `whereis nodejs` again and you should now see a `/mnt/c/...` path and this will confirm that it’s correctly installed within WSL.

---

<div class="post-metadata">

**Author:** ![cell](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cell/32/14140_2.png) [@cell](https://forum.dfinity.org/u/cell)\
**Post date:** [December 8, 2023, 8:46pm UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/8 "2023-12-08T20:46:19Z")

</div>

Oh, right. I installed Node js and still kept running into errors. 🙂 I spent a lot of time googling, but finally my problem was solved by an AI who advised me to replace a piece of code in webpack.config file. Everything worked successfully after I did that. I had almost given up hope, haha. If interested, I can send the latest error text, and the code I used to replace in the original file.

---

<div class="post-metadata">

**Author:** ![NathanosDev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nathanosdev/32/7204_2.png) [@NathanosDev](https://forum.dfinity.org/u/NathanosDev)\
**Post date:** [December 8, 2023, 9:07pm UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/9 "2023-12-08T21:07:39Z")

</div>

Yeah, now I’m very interested to know what was causing this!

---

<div class="post-metadata">

**Author:** ![cell](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cell/32/14140_2.png) [@cell](https://forum.dfinity.org/u/cell)\
**Post date:** [December 9, 2023, 1:34am UTC](https://forum.dfinity.org/t/hello-world-error-failed-while-trying-to-deploy-canisters/25176/10 "2023-12-09T01:34:41Z")

</div>

**Here’s the latest error I’ve gotten in the midst of my battle:**

> Error: Failed while trying to deploy canisters.  
> Caused by: Failed while trying to deploy canisters.  
> Failed to build all canisters.  
> Failed while trying to build all canisters.  
> The post-build step failed for canister ‘y4oop-liaaa-aaaab-qacha-cai’ (hello\_world\_frontend) with an embedded error: Failed to build frontend for network ‘playground’.: The command ‘cd “/home/user/hello\_world” && CANISTER\_CANDID\_PATH=“/home/user/hello\_world/.dfx/playground/canisters/hello\_world\_frontend/assetstorage.did” CANISTER\_CANDID\_PATH\_HELLO\_WORLD\_BACKEND=“/home/user/hello\_world/.dfx/playground/canisters/hello\_world\_backend/hello\_world\_backend.did” CANISTER\_CANDID\_PATH\_hello\_world\_backend=“/home/user/hello\_world/.dfx/playground/canisters/hello\_world\_backend/hello\_world\_backend.did” CANISTER\_ID=“y4oop-liaaa-aaaab-qacha-cai” CANISTER\_ID\_HELLO\_WORLD\_BACKEND=“ofoea-eyaaa-aaaab-qab6a-cai” CANISTER\_ID\_HELLO\_WORLD\_FRONTEND=“y4oop-liaaa-aaaab-qacha-cai” CANISTER\_ID\_hello\_world\_backend=“ofoea-eyaaa-aaaab-qab6a-cai” CANISTER\_ID\_hello\_world\_frontend=“y4oop-liaaa-aaaab-qacha-cai” DFX\_NETWORK=“playground” DFX\_VERSION=“0.15.2” HELLO\_WORLD\_BACKEND\_CANISTER\_ID=“ofoea-eyaaa-aaaab-qab6a-cai” HELLO\_WORLD\_FRONTEND\_CANISTER\_ID=“y4oop-liaaa-aaaab-qacha-cai” “npm” “run” “build”’ failed with exit status ‘exit status: 2’.  
> Stdout:
> 
> > hello\_world\_frontend@0.1.0 prebuild  
> > npm run generate
> 
> > hello\_world\_frontend@0.1.0 generate  
> > dfx generate hello\_world\_backend
> 
> > hello\_world\_frontend@0.1.0 build  
> > webpack
> 
> No production canister\_ids.json found. Continuing with local
> 
> Stderr:  
> Building canisters before generate for Motoko  
> Generating type declarations for canister hello\_world\_backend:  
> src/declarations/hello\_world\_backend/hello\_world\_backend.did.d.ts  
> src/declarations/hello\_world\_backend/hello\_world\_backend.did.js  
> src/declarations/hello\_world\_backend/hello\_world\_backend.did  
> [webpack-cli] Failed to load ‘/home/user/hello\_world/webpack.config.js’ config  
> [webpack-cli] TypeError: Cannot convert undefined or null to object  
> at Function.entries ()  
> at initCanisterEnv (/home/user/hello\_world/webpack.config.js:30:17)  
> at Object. (/home/user/hello\_world/webpack.config.js:37:30)  
> at Module.\_compile (node:internal/modules/cjs/loader:1376:14)  
> at Module.\_extensions…js (node:internal/modules/cjs/loader:1435:10)  
> at Module.load (node:internal/modules/cjs/loader:1207:32)  
> at Module.\_load (node:internal/modules/cjs/loader:1023:12)  
> at Module.require (node:internal/modules/cjs/loader:1235:19)  
> at require (node:internal/modules/helpers:176:18)  
> at WebpackCLI.tryRequireThenImport (/home/user/hello\_world/node\_modules/webpack-cli/lib/webpack-cli.js:204:22)

**Next, I replaced this piece of original code (webpack.config) :**

> function initCanisterEnv() {  
> let localCanisters, prodCanisters;  
> try {  
> localCanisters = require(path.resolve(  
> “.dfx”,  
> “local”,  
> “canister\_ids.json”  
> ));  
> } catch (error) {  
> console.log(“No local canister\_ids.json found. Continuing production”);  
> }  
> try {  
> prodCanisters = require(path.resolve(“canister\_ids.json”));  
> } catch (error) {  
> console.log(“No production canister\_ids.json found. Continuing with local”);  
> }
> 
> const network =  
> process.env.DFX\_NETWORK ||  
> (process.env.NODE\_ENV === “production” ? “ic” : “local”);
> 
> const canisterConfig = network === “local” ? localCanisters : prodCanisters;
> 
> return Object.entries(canisterConfig).reduce((prev, current) =\> {  
> const [canisterName, canisterDetails] = current;  
> prev[canisterName.toUpperCase() + “\_CANISTER\_ID”] =  
> canisterDetails[network];  
> return prev;  
> }, {});  
> }  
> const canisterEnvVariables = initCanisterEnv();

**…replaced it with this. And it worked.**

> function initCanisterEnv() {  
> let localCanisters, prodCanisters;
> 
> try {  
> localCanisters = require(path.resolve(“.dfx”, “local”, “canister\_ids.json”));  
> } catch (error) {  
> console.log(“No local canister\_ids.json found. Continuing production”);  
> }
> 
> try {  
> prodCanisters = require(path.resolve(“canister\_ids.json”));  
> } catch (error) {  
> console.log(“No production canister\_ids.json found. Continuing with local”);  
> }
> 
> const network =  
> process.env.DFX\_NETWORK ||  
> (process.env.NODE\_ENV === “production” ? “ic” : “local”);
> 
> const canisterConfig = network === “local” ? localCanisters : prodCanisters;
> 
> // Check if canisterConfig is defined before using Object.entries  
> if (canisterConfig) {  
> return Object.entries(canisterConfig).reduce((prev, current) =\> {  
> const [canisterName, canisterDetails] = current;  
> prev[canisterName.toUpperCase() + “\_CANISTER\_ID”] =  
> canisterDetails[network];  
> return prev;  
> }, {});  
> }
> 
> return {};  
> }
> 
> const canisterEnvVariables = initCanisterEnv();
