Davis Johnson
Davis Johnson

Reputation: 99

Why does my deno.js terminal work only on a specific path?

I just bought a deno.js course from udemy. The installation was done perfectly but when running a script through deno. It shows an error 'cannot resolve module //filepath'. But when tweaking the path it works perfectly. Here is the code and terminal code below:-


//JAVASCRIPT

function a(){
    console.log(1243);
}
a();


//TERMINAL

PS C:\Users\Intex> deno run deno.js                  
error: Cannot resolve module "file:///C:/Users/Intex/deno.js"         //ERROR


PS C:\Users\Intex> deno run C:\Users\Intex\Desktop\deno.js            //SUCCESSFUL
1243

Upvotes: 2

Views: 308

Answers (4)

David Sherret
David Sherret

Reputation: 106790

PS C:\Users\Intex> deno run deno.js
error: Cannot resolve module "file:///C:/Users/Intex/deno.js" //ERROR

PS C:\Users\Intex> deno run C:\Users\Intex\Desktop\deno.js //SUCCESSFUL 1243

It looks like deno.js is in C:\Users\Intex\Desktop and not the current working directory of C:\Users\Intex.

To run the file at C:\Users\Intex\Desktop\deno.js from C:\Users\Intex using a relative path, you will also need to include the sub directory it's located in:

deno run ./Desktop/deno.js

Upvotes: 1

TechnoTech
TechnoTech

Reputation: 799

You need to provide the relative path of the file with the run command from where you are running the command in the terminal. You can also provide the absolute path. Please take care of forward/backward slashes in the path depending upon the os you are using

Upvotes: 0

David Bedford
David Bedford

Reputation: 26

I just had the same issue, I believe it's to do with the name of the file. I changed it deno_demo.js and it worked fine without having to specify the absolute path.

Upvotes: 1

Aniket Gargya
Aniket Gargya

Reputation: 978

This might be because of Deno itself. You could get around this by always providing the absolute file path or try using the new Windows Terminal because of how it uses paths.

Upvotes: 1

Related Questions