简体   繁体   中英

Uncaught TypeError: Failed to resolve module specifier "prompt-sync". Relative references must start with either "/", "./", or "../"

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.

Related Question Not using node.js : Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../" Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../" Uncaught TypeError: Failed to resolve module specifier “…”. Relative references must start with either “/”, “./”, or “../”. at (index):1 Uncaught TypeError: Failed to resolve module specifier "fs". Relative references must start with either "/", "./", or "../" Why getting Uncaught TypeError: Failed to resolve module specifier "firebase". Relative references must start with either "/", "./", or "../"? Uncaught TypeError: Failed to resolve module specifier “tslib”. Relative references must start with either “/”, “./”, or “../” Failed to resolve module specifier "sortablejs". Relative references must start with either "/", "./", or "../" TypeError: Failed to resolve module specifier “remarkable”. Relative references must start with either “/”, “./”, or “../” Failed to resolve module specifier "vee-validate". Relative references must start with either "/", "./", or "../" Failed to resolve module specifier "socket.io-client". Relative references must start with either "/", "./", or "../"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM