I got some related questions in stack overflow, but I am field to understand the answers. someone, please explain to me what to do.
Here is my JS code
import p from "prompt-sync";
const prompt = p();
//for loop
let sum = 0;
let a = prompt("Enter number :");
for(let i=0;i<=a;i++)
{
sum+=i;
}
console.log(sum);
I called this JS on the HTML page
<script type="module" src="JS/Loop.js"></script>
I am getting this error, in some solutions it mentioned like use URL but which Prompt URL should I have to import instead of prompt-sync
If you give a module name to Node.js then it will search node_modules
to find it.
Browsers can't do that. You need to give them a URL (which will typically end in .js
).
If you want a relative path, then you need to explicitly start that path with ./
(or ../
). You can't just mention the name.
eg
import p from "../scripts/prompt-sync.js"
That said, the module you are trying to use describes itself as:
A sync prompt for node. very simple. no C++ bindings and no bash scripts.
Works on Linux, OS X and Windows.
It makes use of Node.js specific APIs (egvar fs = require('fs');
and process.stdin
).
It isn't going to run in a browser environment.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.