JavaScript Error->Error: Cannot find module 'prompt-sync'

Khan, Zulfi 0 Reputation points
2024-03-21T18:36:09.7933333+00:00

I wrote the following javascript program on VSCode:

try{

const prompt = require("prompt-sync")({sigint: true})

}catch(err){

    ``console.log(err)

}

I am getting th efollowing error message: Error: Cannot find module 'prompt-sync' Following is my code:   Require stack:

  • d:\Varsity Tutor_Lecture\Javascript\programs\posNegZero.js     at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)     at Module._load (node:internal/modules/cjs/loader:985:27)     at Module.require (node:internal/modules/cjs/loader:1235:19)     at require (node:internal/modules/helpers:176:18)     at Object.<anonymous> (d:\Varsity Tutor_Lecture\Javascript\programs\posNegZero.js:2:16)     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 Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {   code: 'MODULE_NOT_FOUND',   requireStack: [ 'd:\Varsity Tutor_Lecture\Javascript\programs\posNegZero.js' ] } d:\Varsity Tutor_Lecture\Javascript\programs\posNegZero.js:6 let val1 = prompt("Input a Number")            ^   ReferenceError: prompt is not defined     at Object.<anonymous> (d:\Varsity Tutor_Lecture\Javascript\programs\posNegZero.js:6:12)     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 Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)     at node:internal/main/run_main_module:28:49   Node.js v20.11.1   [Done] exited with code=1 in 0.101 seconds   I used the following command to install it: C:\Users\zulfi>npm install prompt-sync   added 3 packages, and audited 4 packages in 859ms   found 0 vulnerabilities   C:\Users\zulfi>

Somebody, please guide me what is the problem.

Zulfi.

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
981 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mzoughi Ilyes 80 Reputation points
    2024-03-22T04:04:15.96+00:00

    Hi Khan, Zulfi

    Make sure that you installed the prompt-sync before prompt-sync-history package.
    run this command in node console :

    npm i prompt-sync

    remove the quotes before the ``console.log(err).

    You can test this in a sandbox environment just run

    node index.js
    

    User's image

    https://stackblitz.com/edit/stackblitz-starters-1b8jbe?description=Starter%20project%20for%20Node.js,%20a%20JavaScript%20runtime%20built%20on%20Chrome%27s%20V8%20JavaScript%20engine&file=index.js&title=node.new%20Starter

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.