[英]Cannot find module 'prompt-sync'
I'm making Tic Tac Toe game in JavaScript needed prompt-sync to get user inputs.我在 JavaScript 制作井字游戏需要提示同步才能获得用户输入。 After I installed prompt-sync
module using npm
I was getting this error whenever I tried to run this file.使用npm
安装prompt-sync
模块后,每当我尝试运行此文件时都会收到此错误。 Did a quick google search to find that it requires npm install -g
to activate it globally.快速谷歌搜索发现它需要npm install -g
才能全局激活它。 Despite doing this I'm still getting the same Error.尽管这样做,我仍然遇到同样的错误。 If anyone could please tell what's going wrong here!如果有人能告诉我这里出了什么问题!
Error :错误:
$ node main.js
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'prompt-sync'
Require stack:
- B:\JavaScript Projects\Tic Tac Toe\main.js
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:725:27)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:952:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:88:18)←[39m
at Object.<anonymous> (B:\JavaScript Projects\Tic Tac Toe\main.js:5:16)
←[90m at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [ ←[32m'B:\\JavaScript Projects\\Tic Tac Toe\\main.js'←[39m ]
}
The Code代码
/*
This project implements multiplayer Tic Tac Toe
*/
const prompt = require('prompt-sync')({sigint: true});
const clear_ouput = () => {
for (let i = 1; i < 201; i++) {
console.log();
}
}
const display_board = board => {
clear_ouput();
console.log(' | | ');
console.log(' ' + board[7] + ' | ' + board[8] +' | ' + board[9] + ' ');
console.log(' | | ');
console.log('-----------');
console.log(' | | ');
console.log(' ' + board[4] + ' | ' + board[5] +' | ' + board[6] + ' ');
console.log(' | | ');
console.log('-----------');
console.log(' | | ');
console.log(' ' + board[1] + ' | ' + board[2] +' | ' + board[3] + ' ');
console.log(' | | ');
}
const create_board = char => {
let board = [];
for (let i = 0; i < 11; i++) {
board.push(char);
}
return board;
}
// let game_board = create_board('X');
// display_board(game_board);
const decide_markers = () => {
let marker;
while ( ['X', 'O'].includes(marker) ) {
marker = prompt('Player 1, enter your marker (X - O): ');
if ( !(['X', 'O'].includes(marker)) ) {
console.log(`Sorry but ${marker} is not a valid marker.\nChoose from 'X' or 'O'.\n`);
};
}
if (marker === 'X') {
return ['X', 'O'];
}
return ['O', 'X'];
}
player_markers = decide_markers();
The path of the file is /b/Javascript Projects/Tic Tac Toe
该文件的路径是/b/Javascript Projects/Tic Tac Toe
command used to install prompt-synce npm install -g prompt-sync
用于安装 prompt-synce 的命令npm install -g prompt-sync
I've tried restarting VS Code several times but it's still the same.我试过多次重启 VS Code,但还是一样。
Not sure if you still need it, but for anyone who does:不确定您是否仍然需要它,但对于任何需要它的人:
Try using npm install prompt-sync.尝试使用 npm 安装提示同步。
1.Make sure you have Node and NPM installed 1.确保安装了Node和NPM
2.Run npm install prompt-sync in the terminal 2.在终端运行 npm install prompt-sync
Use this instead in the command prompt (I wrote it while in the same folder as the.js file but that might not be necessary)在命令提示符中使用它(我在与 .js 文件相同的文件夹中编写它,但这可能不是必需的)
npm i prompt-sync npm 我提示同步
Source: https://www.npmjs.com/package/prompt-sync来源: https://www.npmjs.com/package/prompt-sync
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.