babel-node --preset node '." 不被识别为内部或外部命令,



这是package.json中的依赖项

{
"name": "whatsapp",
"version": "1.0.0",
"description": "whatsapp-clone-in-mern-stack",
"main": "server.js",
"scripts": {
"start": "./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js",
"test": "echo "Error: no test specified" && exit 1"
},
"author": "someone",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-preset-node8": "^1.2.0",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.17.1",
"moment": "^2.29.1",
"mongoose": "^6.0.14"
}
}

server.js文件中的代码

import App from "express";
import connectDB from "./dbConnection";
const app = new App();

const PORT = 3001;

const startServer = () => {
Promise.all([connectDB()]).then(() => {
app.listen(PORT);
console.log(`Server started on port ${PORT}`);
});
};

startServer();

index.js文件中的代码

import mongoose from "mongoose";
const DB_CONNECTION_URL = "mongodb://localhost:27017/test";
const connectDB = () => {
console.log("DB trying to connect on " + new Date());
const options = {
keepAlive: 1,
autoReconnect: true,
poolSize: 10,
useNewUrlParser: true,
useUnifiedTopology: true,
};
return mongoose.connect(DB_CONNECTION_URL, options);
};
export default connectDB;

控制台错误

whatsapp@1.0.0 start C:Userskrishonedrivedesktopwhatsapp_clone-mern_Stackwhatsapp-cloneserver
> ./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! whatsapp@1.0.0 start: `./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the whatsapp@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UserskrishAppDataRoamingnpm-cache_logs2021-11-30T
09_26_47_364Z-debug.log

从YouTube教程中学习,我试图制作一个whatsapp克隆。我想使用babel-cli和babel-node来启动服务器,以便连接数据库,所以我在脚本中编写了这段代码{quot;./node_modules/babel-cli/bin/babel-node.js--presets node8./server.js"},但它显示了上述错误。请帮帮我。

您遇到的错误是由于在Windows中使用*nix路径语法造成的。尝试用windows反斜杠写入路径,或者尝试babel-node --presets node8 .server.js

编写此

"scripts": {
"start": "node ./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js",
"test": "echo "Error: no test specified" && exit 1"
}, 

而不是这个

"scripts": {
"start": "./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js",
"test": "echo "Error: no test specified" && exit 1"
},

相关内容

  • 没有找到相关文章

最新更新